Skip to content

Commit

Permalink
HHH-6589 - Skip non-JPA features populating JPA "static metamodel"
Browse files Browse the repository at this point in the history
  • Loading branch information
mam authored and sebersole committed Mar 2, 2012
1 parent 2f280b0 commit f4c9b28
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
Expand Up @@ -90,9 +90,12 @@ public EntityManagerFactoryImpl(
this.discardOnClose = discardOnClose;
this.sessionInterceptorClass = sessionInterceptorClass;
final Iterator<PersistentClass> classes = cfg.getClassMappings();
//a safe guard till we are confident that metamodel is wll tested
if ( !"disabled".equalsIgnoreCase( cfg.getProperty( "hibernate.ejb.metamodel.generation" ) ) ) {
this.metamodel = MetamodelImpl.buildMetamodel( classes, ( SessionFactoryImplementor ) sessionFactory );
//a safe guard till we are confident that metamodel is well tested
// disabled: dont create metamodel
// ignoreUnsupported: create metamodel, but ignore unsupported/unknown annotations (like @Any) HHH-6589
final String ejbMetamodelGenerationProperty = cfg.getProperty( "hibernate.ejb.metamodel.generation" );
if ( !"disabled".equalsIgnoreCase( ejbMetamodelGenerationProperty ) ) {
this.metamodel = MetamodelImpl.buildMetamodel( classes, ( SessionFactoryImplementor ) sessionFactory, "ignoreUnsupported".equalsIgnoreCase( ejbMetamodelGenerationProperty ));
}
else {
this.metamodel = null;
Expand Down
Expand Up @@ -90,7 +90,7 @@ public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> o
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final AttributeMetadata<X,Y> attributeMetadata =
determineAttributeMetadata( attributeContext, NORMAL_MEMBER_RESOLVER );

if (attributeMetadata == null) return null;
if (attributeMetadata.isPlural()) return buildPluralAttribute((PluralAttributeMetadata)attributeMetadata);
final SingularAttributeMetadata<X, Y> singularAttributeMetadata = (SingularAttributeMetadata<X, Y>)attributeMetadata;
final Type<Y> metaModelType = getMetaModelType(singularAttributeMetadata.getValueContext());
Expand Down Expand Up @@ -428,7 +428,12 @@ private <X,Y> AttributeMetadata<X,Y> determineAttributeMetadata(
LOG.trace(" Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]");

if ( type.isAnyType() ) {
throw new UnsupportedOperationException( "any not supported yet" );
if ( context.isIgnoreUnsupported() ) {
// HHH-6589 Support "Any" mappings when building metamodel
return null;
} else {
throw new UnsupportedOperationException( "any not supported yet" );
}
}
else if ( type.isAssociationType() ) {
// collection or entity
Expand Down
Expand Up @@ -61,6 +61,7 @@ class MetadataContext {
MetadataContext.class.getName());

private final SessionFactoryImplementor sessionFactory;
private final boolean ignoreUnsupported;
private final AttributeFactory attributeFactory = new AttributeFactory( this );

private Map<Class<?>,EntityTypeImpl<?>> entityTypes
Expand All @@ -84,15 +85,20 @@ class MetadataContext {
private Map<MappedSuperclassTypeImpl<?>, PersistentClass> mappedSuperClassTypeToPersistentClass
= new HashMap<MappedSuperclassTypeImpl<?>, PersistentClass>();

public MetadataContext(SessionFactoryImplementor sessionFactory) {
public MetadataContext(SessionFactoryImplementor sessionFactory, boolean ignoreUnsupported) {
this.sessionFactory = sessionFactory;
this.ignoreUnsupported = ignoreUnsupported;
}

/*package*/ SessionFactoryImplementor getSessionFactory() {
return sessionFactory;
}

/**
/*package*/ boolean isIgnoreUnsupported() {
return ignoreUnsupported;
}

/**
* Retrieves the {@linkplain Class java type} to {@link EntityTypeImpl} map.
*
* @return The {@linkplain Class java type} to {@link EntityTypeImpl} map.
Expand Down
Expand Up @@ -43,18 +43,34 @@ public class MetamodelImpl implements Metamodel, Serializable {
private final Map<Class<?>,EntityTypeImpl<?>> entities;
private final Map<Class<?>, EmbeddableTypeImpl<?>> embeddables;

/**
* Build the metamodel using the information from the collection of Hibernate
* {@link PersistentClass} models as well as the Hibernate {@link org.hibernate.SessionFactory}.
*
* @param persistentClasses Iterator over the Hibernate (config-time) metamodel
* @param sessionFactory The Hibernate session factry.
* @return The built metamodel
*/
public static MetamodelImpl buildMetamodel(
Iterator<PersistentClass> persistentClasses,
SessionFactoryImplementor sessionFactory) {
return buildMetamodel(persistentClasses, sessionFactory, false);
}

/**
* Build the metamodel using the information from the collection of Hibernate
* {@link PersistentClass} models as well as the Hibernate {@link org.hibernate.SessionFactory}.
*
* @param persistentClasses Iterator over the Hibernate (config-time) metamodel
* @param sessionFactory The Hibernate session factry.
* @param ignoreUnsupported ignore unsupported/unknown annotations (like @Any)
* @return The built metamodel
*/
public static MetamodelImpl buildMetamodel(
Iterator<PersistentClass> persistentClasses,
SessionFactoryImplementor sessionFactory) {
MetadataContext context = new MetadataContext( sessionFactory );
SessionFactoryImplementor sessionFactory,
boolean ignoreUnsupported) {
MetadataContext context = new MetadataContext( sessionFactory, ignoreUnsupported );
while ( persistentClasses.hasNext() ) {
PersistentClass pc = persistentClasses.next();
if ( pc.getMappedClass() != null ) {
Expand Down

0 comments on commit f4c9b28

Please sign in to comment.