Search in sources :

Example 1 with Lob

use of javax.persistence.Lob in project hibernate-orm by hibernate.

the class PropertyBinder method makeProperty.

//used when the value is provided and the binding is done elsewhere
public Property makeProperty() {
    validateMake();
    LOG.debugf("Building property %s", name);
    Property prop = new Property();
    prop.setName(name);
    prop.setValue(value);
    prop.setLazy(lazy);
    prop.setLazyGroup(lazyGroup);
    prop.setCascade(cascade);
    prop.setPropertyAccessorName(accessType.getType());
    if (property != null) {
        prop.setValueGenerationStrategy(determineValueGenerationStrategy(property));
    }
    NaturalId naturalId = property != null ? property.getAnnotation(NaturalId.class) : null;
    if (naturalId != null) {
        if (!entityBinder.isRootEntity()) {
            throw new AnnotationException("@NaturalId only valid on root entity (or its @MappedSuperclasses)");
        }
        if (!naturalId.mutable()) {
            updatable = false;
        }
        prop.setNaturalIdentifier(true);
    }
    // HHH-4635 -- needed for dialect-specific property ordering
    Lob lob = property != null ? property.getAnnotation(Lob.class) : null;
    prop.setLob(lob != null);
    prop.setInsertable(insertable);
    prop.setUpdateable(updatable);
    // this is already handled for collections in CollectionBinder...
    if (Collection.class.isInstance(value)) {
        prop.setOptimisticLocked(((Collection) value).isOptimisticLocked());
    } else {
        final OptimisticLock lockAnn = property != null ? property.getAnnotation(OptimisticLock.class) : null;
        if (lockAnn != null) {
            //TODO this should go to the core as a mapping validation checking
            if (lockAnn.excluded() && (property.isAnnotationPresent(javax.persistence.Version.class) || property.isAnnotationPresent(Id.class) || property.isAnnotationPresent(EmbeddedId.class))) {
                throw new AnnotationException("@OptimisticLock.exclude=true incompatible with @Id, @EmbeddedId and @Version: " + StringHelper.qualify(holder.getPath(), name));
            }
        }
        // && updatable as well???
        final boolean isOwnedValue = !isToOneValue(value) || insertable;
        final boolean includeInOptimisticLockChecks = (lockAnn != null) ? !lockAnn.excluded() : isOwnedValue;
        prop.setOptimisticLocked(includeInOptimisticLockChecks);
    }
    LOG.tracev("Cascading {0} with {1}", name, cascade);
    this.mappingProperty = prop;
    return prop;
}
Also used : AnnotationException(org.hibernate.AnnotationException) EmbeddedId(javax.persistence.EmbeddedId) Property(org.hibernate.mapping.Property) XProperty(org.hibernate.annotations.common.reflection.XProperty) NaturalId(org.hibernate.annotations.NaturalId) OptimisticLock(org.hibernate.annotations.OptimisticLock) Lob(javax.persistence.Lob)

Aggregations

EmbeddedId (javax.persistence.EmbeddedId)1 Lob (javax.persistence.Lob)1 AnnotationException (org.hibernate.AnnotationException)1 NaturalId (org.hibernate.annotations.NaturalId)1 OptimisticLock (org.hibernate.annotations.OptimisticLock)1 XProperty (org.hibernate.annotations.common.reflection.XProperty)1 Property (org.hibernate.mapping.Property)1