HHH-7655 @Temporal should not be required on Date/Calendar fields
This commit is contained in:
parent
5dd5e251ba
commit
e1a669add0
|
@ -40,6 +40,7 @@ import org.hibernate.type.StandardBasicTypes;
|
|||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
||||
private final BasicAttribute mappedAttribute;
|
||||
|
@ -54,18 +55,24 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
|||
|
||||
@Override
|
||||
public String resolveHibernateTypeName(AnnotationInstance temporalAnnotation) {
|
||||
Class attributeType = mappedAttribute.getAttributeType();
|
||||
|
||||
if ( isTemporalType( mappedAttribute.getAttributeType() ) ) {
|
||||
if ( isTemporalType( attributeType ) ) {
|
||||
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." );
|
||||
// Although JPA 2.1 states that @Temporal is required on
|
||||
// Date/Calendar attributes, allow it to be left off in order
|
||||
// to support legacy mappings.
|
||||
if ( Calendar.class.isAssignableFrom( attributeType ) ) {
|
||||
return StandardBasicTypes.CALENDAR.getName();
|
||||
} else {
|
||||
return StandardBasicTypes.TIMESTAMP.getName();
|
||||
}
|
||||
} else {
|
||||
final TemporalType temporalType = JandexHelper.getEnumValue( temporalAnnotation, "value", TemporalType.class );
|
||||
final boolean isDate = Date.class.isAssignableFrom( mappedAttribute.getAttributeType() );
|
||||
final boolean isDate = Date.class.isAssignableFrom( attributeType );
|
||||
String type;
|
||||
switch ( temporalType ) {
|
||||
case DATE:
|
||||
|
@ -85,7 +92,7 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
|||
}
|
||||
return type;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ( temporalAnnotation != null ) {
|
||||
throw new AnnotationException(
|
||||
"@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + mappedAttribute
|
||||
|
|
Loading…
Reference in New Issue