HHH-6520 Construction of type resolver needs to be deferred

This commit is contained in:
Hardy Ferentschik 2011-08-01 15:22:43 +02:00
parent f2338af9eb
commit b8cc897bee
1 changed files with 21 additions and 19 deletions

View File

@ -46,9 +46,9 @@ import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.JandexHelper; import org.hibernate.metamodel.source.annotations.JandexHelper;
import org.hibernate.metamodel.source.annotations.TypeEnumConversionHelper; import org.hibernate.metamodel.source.annotations.TypeEnumConversionHelper;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver; import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolver;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolverImpl;
import org.hibernate.metamodel.source.annotations.attribute.type.CompositeAttributeTypeResolver; import org.hibernate.metamodel.source.annotations.attribute.type.CompositeAttributeTypeResolver;
import org.hibernate.metamodel.source.annotations.attribute.type.EnumeratedTypeResolver; import org.hibernate.metamodel.source.annotations.attribute.type.EnumeratedTypeResolver;
import org.hibernate.metamodel.source.annotations.attribute.type.AttributeTypeResolverImpl;
import org.hibernate.metamodel.source.annotations.attribute.type.LobTypeResolver; import org.hibernate.metamodel.source.annotations.attribute.type.LobTypeResolver;
import org.hibernate.metamodel.source.annotations.attribute.type.TemporalTypeResolver; import org.hibernate.metamodel.source.annotations.attribute.type.TemporalTypeResolver;
@ -105,7 +105,7 @@ public class BasicAttribute extends MappedAttribute {
private final String customWriteFragment; private final String customWriteFragment;
private final String customReadFragment; private final String customReadFragment;
private final String checkCondition; private final String checkCondition;
private final AttributeTypeResolver resolver; private AttributeTypeResolver resolver;
public static BasicAttribute createSimpleAttribute(String name, public static BasicAttribute createSimpleAttribute(String name,
Class<?> attributeType, Class<?> attributeType,
@ -127,7 +127,7 @@ public class BasicAttribute extends MappedAttribute {
annotations, annotations,
JPADotNames.EMBEDDED_ID JPADotNames.EMBEDDED_ID
); );
//if this attribute has either @Id or @EmbeddedId, then it is an id attribute //if this attribute has either @Id or @EmbeddedId, then it is an id attribute
isId = ( idAnnotation != null || embeddedIdAnnotation != null ); isId = ( idAnnotation != null || embeddedIdAnnotation != null );
AnnotationInstance versionAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.VERSION ); AnnotationInstance versionAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.VERSION );
@ -156,7 +156,6 @@ public class BasicAttribute extends MappedAttribute {
this.customReadFragment = readWrite[0]; this.customReadFragment = readWrite[0];
this.customWriteFragment = readWrite[1]; this.customWriteFragment = readWrite[1];
this.checkCondition = parseCheckAnnotation(); this.checkCondition = parseCheckAnnotation();
this.resolver = getDefaultHibernateTypeResolver();
} }
public final ColumnValues getColumnValues() { public final ColumnValues getColumnValues() {
@ -357,22 +356,25 @@ public class BasicAttribute extends MappedAttribute {
return generator; return generator;
} }
@Override @Override
public AttributeTypeResolver getHibernateTypeResolver() { public AttributeTypeResolver getHibernateTypeResolver() {
return resolver; if ( resolver == null ) {
} resolver = getDefaultHibernateTypeResolver();
}
return resolver;
}
private AttributeTypeResolver getDefaultHibernateTypeResolver() { private AttributeTypeResolver getDefaultHibernateTypeResolver() {
CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver( CompositeAttributeTypeResolver resolver = new CompositeAttributeTypeResolver(
new AttributeTypeResolverImpl( new AttributeTypeResolverImpl(
this this
) )
); );
resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) ); resolver.addHibernateTypeResolver( new TemporalTypeResolver( this ) );
resolver.addHibernateTypeResolver( new LobTypeResolver( this ) ); resolver.addHibernateTypeResolver( new LobTypeResolver( this ) );
resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) ); resolver.addHibernateTypeResolver( new EnumeratedTypeResolver( this ) );
return resolver; return resolver;
} }
} }