diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java index 9c1d484e4c..832fd1d935 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/BasicAttribute.java @@ -36,6 +36,7 @@ import org.hibernate.AnnotationException; import org.hibernate.annotations.GenerationTime; +import org.hibernate.annotations.SourceType; import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.PropertyGeneration; import org.hibernate.metamodel.spi.binding.IdGenerator; @@ -70,6 +71,9 @@ public class BasicAttribute extends MappedAttribute { */ private final boolean isVersioned; + + private final SourceType versionSourceType; + /** * Is this property lazy loaded (see {@link javax.persistence.Basic}). */ @@ -110,6 +114,22 @@ public static BasicAttribute createSimpleAttribute(String name, AnnotationInstance versionAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.VERSION ); isVersioned = versionAnnotation != null; + if ( isVersioned ) { + AnnotationInstance sourceAnnotation = JandexHelper.getSingleAnnotation( + annotations, + HibernateDotNames.SOURCE + ); + if ( sourceAnnotation != null ) { + versionSourceType = JandexHelper.getEnumValue( sourceAnnotation, "value", SourceType.class ); + } + else { + versionSourceType = null; + } + } + else { + versionSourceType = null; + } + if ( isId() ) { // an id must be unique and cannot be nullable getColumnValues().setUnique( true ); @@ -170,6 +190,11 @@ public IdGenerator getIdGenerator() { return idGenerator; } + public SourceType getVersionSourceType() { + return versionSourceType; + } + + @Override public String toString() { final StringBuilder sb = new StringBuilder(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java index f0710c76dd..1ac11f84ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/attribute/type/TemporalTypeResolver.java @@ -32,9 +32,11 @@ import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; +import org.hibernate.annotations.SourceType; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.metamodel.internal.source.annotations.JPADotNames; import org.hibernate.metamodel.internal.source.annotations.JandexHelper; +import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.MappedAttribute; import org.hibernate.type.StandardBasicTypes; @@ -42,10 +44,9 @@ * @author Strong Liu */ public class TemporalTypeResolver extends AbstractAttributeTypeResolver { - private final MappedAttribute mappedAttribute; + private final BasicAttribute mappedAttribute; private final boolean isMapKey; - - public TemporalTypeResolver(MappedAttribute mappedAttribute) { + public TemporalTypeResolver(BasicAttribute mappedAttribute) { if ( mappedAttribute == null ) { throw new AssertionFailure( "MappedAttribute is null" ); } @@ -57,12 +58,16 @@ public TemporalTypeResolver(MappedAttribute mappedAttribute) { public String resolveHibernateTypeName(AnnotationInstance temporalAnnotation) { if ( isTemporalType( mappedAttribute.getAttributeType() ) ) { + if ( mappedAttribute.isVersioned() && mappedAttribute.getVersionSourceType() != null ) { + return mappedAttribute.getVersionSourceType().typeName(); + } if ( temporalAnnotation == null ) { //SPEC 11.1.47 The Temporal annotation must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar. + //todo actually the legacy mapping doesn't require this throw new AnnotationException( "Attribute " + mappedAttribute.getName() + " is a Temporal type, but no @Temporal annotation found." ); } - TemporalType temporalType = JandexHelper.getEnumValue( temporalAnnotation, "value", TemporalType.class ); - boolean isDate = Date.class.isAssignableFrom( mappedAttribute.getAttributeType() ); + final TemporalType temporalType = JandexHelper.getEnumValue( temporalAnnotation, "value", TemporalType.class ); + final boolean isDate = Date.class.isAssignableFrom( mappedAttribute.getAttributeType() ); String type; switch ( temporalType ) { case DATE: