Search in sources :

Example 1 with IdentifierSourceNonAggregatedComposite

use of org.hibernate.boot.model.source.spi.IdentifierSourceNonAggregatedComposite in project hibernate-orm by hibernate.

the class ModelBinder method bindNonAggregatedCompositeEntityIdentifier.

private void bindNonAggregatedCompositeEntityIdentifier(MappingDocument mappingDocument, EntityHierarchySourceImpl hierarchySource, RootClass rootEntityDescriptor) {
    final IdentifierSourceNonAggregatedComposite identifierSource = (IdentifierSourceNonAggregatedComposite) hierarchySource.getIdentifierSource();
    final Component cid = new Component(mappingDocument.getMetadataCollector(), rootEntityDescriptor);
    cid.setKey(true);
    rootEntityDescriptor.setIdentifier(cid);
    final String idClassName = extractIdClassName(identifierSource);
    bindComponent(mappingDocument, hierarchySource.getRoot().getAttributeRoleBase().append("<id>").getFullPath(), identifierSource.getEmbeddableSource(), cid, idClassName, rootEntityDescriptor.getClassName(), null, idClassName == null, false, null);
    if (idClassName != null) {
        // we also need to bind the "id mapper".  ugh, terrible name.  Basically we need to
        // create a virtual (embedded) composite for the non-aggregated attributes on the entity
        // itself.
        final Component mapper = new Component(mappingDocument.getMetadataCollector(), rootEntityDescriptor);
        bindComponent(mappingDocument, hierarchySource.getRoot().getAttributeRoleBase().append(ID_MAPPER_PATH_PART).getFullPath(), identifierSource.getEmbeddableSource(), mapper, rootEntityDescriptor.getClassName(), null, null, true, false, null);
        rootEntityDescriptor.setIdentifierMapper(mapper);
        Property property = new Property();
        property.setName(PropertyPath.IDENTIFIER_MAPPER_PROPERTY);
        property.setUpdateable(false);
        property.setInsertable(false);
        property.setValue(mapper);
        property.setPropertyAccessorName("embedded");
        rootEntityDescriptor.addProperty(property);
    }
    finishBindingCompositeIdentifier(mappingDocument, rootEntityDescriptor, identifierSource, cid, null);
}
Also used : IdentifierSourceNonAggregatedComposite(org.hibernate.boot.model.source.spi.IdentifierSourceNonAggregatedComposite) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Aggregations

IdentifierSourceNonAggregatedComposite (org.hibernate.boot.model.source.spi.IdentifierSourceNonAggregatedComposite)1 Component (org.hibernate.mapping.Component)1 Property (org.hibernate.mapping.Property)1 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)1