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 Strong Liu
|
||||||
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
||||||
private final BasicAttribute mappedAttribute;
|
private final BasicAttribute mappedAttribute;
|
||||||
|
@ -54,18 +55,24 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resolveHibernateTypeName(AnnotationInstance temporalAnnotation) {
|
public String resolveHibernateTypeName(AnnotationInstance temporalAnnotation) {
|
||||||
|
Class attributeType = mappedAttribute.getAttributeType();
|
||||||
|
|
||||||
if ( isTemporalType( mappedAttribute.getAttributeType() ) ) {
|
if ( isTemporalType( attributeType ) ) {
|
||||||
if ( mappedAttribute.isVersioned() && mappedAttribute.getVersionSourceType() != null ) {
|
if ( mappedAttribute.isVersioned() && mappedAttribute.getVersionSourceType() != null ) {
|
||||||
return mappedAttribute.getVersionSourceType().typeName();
|
return mappedAttribute.getVersionSourceType().typeName();
|
||||||
}
|
}
|
||||||
if ( temporalAnnotation == null ) {
|
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.
|
// Although JPA 2.1 states that @Temporal is required on
|
||||||
//todo actually the legacy mapping doesn't require this
|
// Date/Calendar attributes, allow it to be left off in order
|
||||||
throw new AnnotationException( "Attribute " + mappedAttribute.getName() + " is a Temporal type, but no @Temporal annotation found." );
|
// 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 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;
|
String type;
|
||||||
switch ( temporalType ) {
|
switch ( temporalType ) {
|
||||||
case DATE:
|
case DATE:
|
||||||
|
@ -85,7 +92,7 @@ public class TemporalTypeResolver extends AbstractAttributeTypeResolver {
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
if ( temporalAnnotation != null ) {
|
if ( temporalAnnotation != null ) {
|
||||||
throw new AnnotationException(
|
throw new AnnotationException(
|
||||||
"@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + mappedAttribute
|
"@Temporal should only be set on a java.util.Date or java.util.Calendar property: " + mappedAttribute
|
||||||
|
|
Loading…
Reference in New Issue