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);
}
}
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());
}
Aggregations