Search in sources :

Example 1 with TimeZoneStorage

use of org.hibernate.annotations.TimeZoneStorage 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());
        };
    }
}
Also used : MapKeyEnumerated(jakarta.persistence.MapKeyEnumerated) Enumerated(jakarta.persistence.Enumerated) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) Temporal(jakarta.persistence.Temporal) MapKeyTemporal(jakarta.persistence.MapKeyTemporal) ElementCollection(jakarta.persistence.ElementCollection) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) XClass(org.hibernate.annotations.common.reflection.XClass) TimeZoneStorage(org.hibernate.annotations.TimeZoneStorage)

Aggregations

ElementCollection (jakarta.persistence.ElementCollection)1 Enumerated (jakarta.persistence.Enumerated)1 MapKeyEnumerated (jakarta.persistence.MapKeyEnumerated)1 MapKeyTemporal (jakarta.persistence.MapKeyTemporal)1 Temporal (jakarta.persistence.Temporal)1 TimeZoneStorage (org.hibernate.annotations.TimeZoneStorage)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 BasicJavaType (org.hibernate.type.descriptor.java.BasicJavaType)1 TypeConfiguration (org.hibernate.type.spi.TypeConfiguration)1