Search in sources :

Example 6 with Any

use of org.hibernate.mapping.Any in project hibernate-orm by hibernate.

the class ModelBinder method bindAllCompositeAttributes.

private void bindAllCompositeAttributes(MappingDocument sourceDocument, EmbeddableSource embeddableSource, Component component) {
    for (AttributeSource attributeSource : embeddableSource.attributeSources()) {
        Property attribute = null;
        if (SingularAttributeSourceBasic.class.isInstance(attributeSource)) {
            attribute = createBasicAttribute(sourceDocument, (SingularAttributeSourceBasic) attributeSource, new SimpleValue(sourceDocument.getMetadataCollector(), component.getTable()), component.getComponentClassName());
        } else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
            attribute = createEmbeddedAttribute(sourceDocument, (SingularAttributeSourceEmbedded) attributeSource, new Component(sourceDocument.getMetadataCollector(), component), component.getComponentClassName());
        } else if (SingularAttributeSourceManyToOne.class.isInstance(attributeSource)) {
            attribute = createManyToOneAttribute(sourceDocument, (SingularAttributeSourceManyToOne) attributeSource, new ManyToOne(sourceDocument.getMetadataCollector(), component.getTable()), component.getComponentClassName());
        } else if (SingularAttributeSourceOneToOne.class.isInstance(attributeSource)) {
            attribute = createOneToOneAttribute(sourceDocument, (SingularAttributeSourceOneToOne) attributeSource, new OneToOne(sourceDocument.getMetadataCollector(), component.getTable(), component.getOwner()), component.getComponentClassName());
        } else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
            attribute = createAnyAssociationAttribute(sourceDocument, (SingularAttributeSourceAny) attributeSource, new Any(sourceDocument.getMetadataCollector(), component.getTable()), component.getComponentClassName());
        } else if (PluralAttributeSource.class.isInstance(attributeSource)) {
            attribute = createPluralAttribute(sourceDocument, (PluralAttributeSource) attributeSource, component.getOwner());
        } else {
            throw new AssertionFailure(String.format(Locale.ENGLISH, "Unexpected AttributeSource sub-type [%s] as part of composite [%s]", attributeSource.getClass().getName(), attributeSource.getAttributeRole().getFullPath()));
        }
        component.addProperty(attribute);
    }
}
Also used : SingularAttributeSourceBasic(org.hibernate.boot.model.source.spi.SingularAttributeSourceBasic) VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) AttributeSource(org.hibernate.boot.model.source.spi.AttributeSource) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) SingularAttributeSource(org.hibernate.boot.model.source.spi.SingularAttributeSource) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) AssertionFailure(org.hibernate.AssertionFailure) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) PluralAttributeElementSourceManyToAny(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny) Any(org.hibernate.mapping.Any) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) SingularAttributeSourceEmbedded(org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) OneToOne(org.hibernate.mapping.OneToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Example 7 with Any

use of org.hibernate.mapping.Any in project hibernate-orm by hibernate.

the class AnnotationBinder method bindAny.

private static void bindAny(String cascadeStrategy, Ejb3JoinColumn[] columns, boolean cascadeOnDelete, Nullability nullability, PropertyHolder propertyHolder, PropertyData inferredData, EntityBinder entityBinder, boolean isIdentifierMapper, MetadataBuildingContext buildingContext) {
    org.hibernate.annotations.Any anyAnn = inferredData.getProperty().getAnnotation(org.hibernate.annotations.Any.class);
    if (anyAnn == null) {
        throw new AssertionFailure("Missing @Any annotation: " + BinderHelper.getPath(propertyHolder, inferredData));
    }
    Any value = BinderHelper.buildAnyValue(anyAnn.metaDef(), columns, anyAnn.metaColumn(), inferredData, cascadeOnDelete, nullability, propertyHolder, entityBinder, anyAnn.optional(), buildingContext);
    PropertyBinder binder = new PropertyBinder();
    binder.setName(inferredData.getPropertyName());
    binder.setValue(value);
    binder.setLazy(anyAnn.fetch() == FetchType.LAZY);
    //binder.setCascade(cascadeStrategy);
    if (isIdentifierMapper) {
        binder.setInsertable(false);
        binder.setUpdatable(false);
    } else {
        binder.setInsertable(columns[0].isInsertable());
        binder.setUpdatable(columns[0].isUpdatable());
    }
    binder.setAccessType(inferredData.getDefaultAccess());
    binder.setCascade(cascadeStrategy);
    Property prop = binder.makeProperty();
    //composite FK columns are in the same table so its OK
    propertyHolder.addProperty(prop, columns, inferredData.getDeclaringClass());
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) PropertyBinder(org.hibernate.cfg.annotations.PropertyBinder) Any(org.hibernate.mapping.Any) ManyToAny(org.hibernate.annotations.ManyToAny) Property(org.hibernate.mapping.Property) XProperty(org.hibernate.annotations.common.reflection.XProperty)

Aggregations

Any (org.hibernate.mapping.Any)7 Component (org.hibernate.mapping.Component)5 ManyToOne (org.hibernate.mapping.ManyToOne)5 Property (org.hibernate.mapping.Property)4 SimpleValue (org.hibernate.mapping.SimpleValue)4 AssertionFailure (org.hibernate.AssertionFailure)3 PluralAttributeElementSourceManyToAny (org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny)3 SingularAttributeSourceAny (org.hibernate.boot.model.source.spi.SingularAttributeSourceAny)3 SingularAttributeSourceManyToOne (org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne)3 OneToOne (org.hibernate.mapping.OneToOne)3 Table (org.hibernate.mapping.Table)3 HashMap (java.util.HashMap)2 AnnotationException (org.hibernate.AnnotationException)2 MappingException (org.hibernate.MappingException)2 ManyToAny (org.hibernate.annotations.ManyToAny)2 XProperty (org.hibernate.annotations.common.reflection.XProperty)2 Identifier (org.hibernate.boot.model.naming.Identifier)2 AttributeSource (org.hibernate.boot.model.source.spi.AttributeSource)2 PluralAttributeSource (org.hibernate.boot.model.source.spi.PluralAttributeSource)2 SingularAttributeSource (org.hibernate.boot.model.source.spi.SingularAttributeSource)2