use of jakarta.persistence.Temporal in project hibernate-orm by hibernate.
the class BasicValueBinder method prepareBasicAttribute.
private void prepareBasicAttribute(String declaringClassName, XProperty attributeDescriptor, XClass attributeType) {
final Class<?> javaType = resolveJavaType(attributeType);
implicitJavaTypeAccess = typeConfiguration -> javaType;
final Temporal temporalAnn = attributeDescriptor.getAnnotation(Temporal.class);
if (temporalAnn != null) {
this.temporalPrecision = temporalAnn.value();
if (this.temporalPrecision == null) {
throw new IllegalStateException("No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + "associated with attribute " + attributeDescriptor.getDeclaringClass().getName() + '.' + attributeDescriptor.getName());
}
} else {
this.temporalPrecision = null;
}
if (javaType.isEnum()) {
final Enumerated enumeratedAnn = attributeDescriptor.getAnnotation(Enumerated.class);
if (enumeratedAnn != null) {
this.enumType = enumeratedAnn.value();
if (this.enumType == null) {
throw new IllegalStateException("jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + " associated with attribute " + attributeDescriptor.getDeclaringClass().getName() + '.' + attributeDescriptor.getName());
}
}
} else {
if (attributeDescriptor.isAnnotationPresent(Enumerated.class)) {
throw new AnnotationException(String.format("Attribute [%s.%s] was annotated as enumerated, but its java type is not an enum [%s]", declaringClassName, attributeDescriptor.getName(), attributeType.getName()));
}
this.enumType = null;
}
normalSupplementalDetails(attributeDescriptor);
}
use of jakarta.persistence.Temporal in project hibernate-orm by hibernate.
the class BasicValueBinder method normalSupplementalDetails.
private void normalSupplementalDetails(XProperty attributeXProperty) {
explicitJavaTypeAccess = typeConfiguration -> {
final org.hibernate.annotations.JavaType javaTypeAnn = findAnnotation(attributeXProperty, org.hibernate.annotations.JavaType.class);
if (javaTypeAnn != null) {
final Class<? extends BasicJavaType<?>> javaType = normalizeJavaType(javaTypeAnn.value());
if (javaType != null) {
final ManagedBean<? extends BasicJavaType<?>> jtdBean = getManagedBeanRegistry().getBean(javaType);
return jtdBean.getBeanInstance();
}
}
final Target targetAnn = findAnnotation(attributeXProperty, Target.class);
if (targetAnn != null) {
return (BasicJavaType<?>) typeConfiguration.getJavaTypeRegistry().getDescriptor(targetAnn.value());
}
return null;
};
normalJdbcTypeDetails(attributeXProperty);
normalMutabilityDetails(attributeXProperty);
final Enumerated enumeratedAnn = attributeXProperty.getAnnotation(Enumerated.class);
if (enumeratedAnn != null) {
enumType = enumeratedAnn.value();
}
final Temporal temporalAnn = attributeXProperty.getAnnotation(Temporal.class);
if (temporalAnn != null) {
temporalPrecision = temporalAnn.value();
}
}
use of jakarta.persistence.Temporal in project hibernate-orm by hibernate.
the class BasicValueBinder method prepareCollectionElement.
private void prepareCollectionElement(XProperty attributeXProperty, XClass elementTypeXClass) {
XClass xclass = elementTypeXClass == null && attributeXProperty.isArray() ? attributeXProperty.getElementClass() : elementTypeXClass;
Class<?> javaType = resolveJavaType(xclass);
implicitJavaTypeAccess = typeConfiguration -> javaType;
final Temporal temporalAnn = attributeXProperty.getAnnotation(Temporal.class);
if (temporalAnn != null) {
temporalPrecision = temporalAnn.value();
if (temporalPrecision == null) {
throw new IllegalStateException("No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + "associated with attribute " + attributeXProperty.getDeclaringClass().getName() + '.' + attributeXProperty.getName());
}
} else {
temporalPrecision = null;
}
if (javaType.isEnum()) {
final Enumerated enumeratedAnn = attributeXProperty.getAnnotation(Enumerated.class);
if (enumeratedAnn != null) {
enumType = enumeratedAnn.value();
if (enumType == null) {
throw new IllegalStateException("jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + " associated with attribute " + attributeXProperty.getDeclaringClass().getName() + '.' + attributeXProperty.getName());
}
}
} else {
enumType = null;
}
final TimeZoneStorage timeZoneStorageAnn = attributeXProperty.getAnnotation(TimeZoneStorage.class);
timeZoneStorageType = timeZoneStorageAnn != null ? timeZoneStorageAnn.value() : null;
normalSupplementalDetails(attributeXProperty);
// layer in support for JPA's approach for specifying a specific Java type for the collection elements...
final ElementCollection elementCollectionAnn = attributeXProperty.getAnnotation(ElementCollection.class);
if (elementCollectionAnn != null && elementCollectionAnn.targetClass() != null && elementCollectionAnn.targetClass() != void.class) {
final Function<TypeConfiguration, BasicJavaType> original = explicitJavaTypeAccess;
explicitJavaTypeAccess = (typeConfiguration) -> {
final BasicJavaType<?> originalResult = original.apply(typeConfiguration);
if (originalResult != null) {
return originalResult;
}
return (BasicJavaType<?>) typeConfiguration.getJavaTypeRegistry().getDescriptor(elementCollectionAnn.targetClass());
};
}
}
Aggregations