Search in sources :

Example 1 with EntityTableXref

use of org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref in project hibernate-orm by hibernate.

the class ModelBinder method bindEntityTableSpecification.

private Table bindEntityTableSpecification(final MappingDocument mappingDocument, TableSpecificationSource tableSpecSource, Table denormalizedSuperTable, final EntitySource entitySource, PersistentClass entityDescriptor) {
    final Namespace namespace = database.locateNamespace(determineCatalogName(tableSpecSource), determineSchemaName(tableSpecSource));
    final boolean isTable = TableSource.class.isInstance(tableSpecSource);
    final boolean isAbstract = entityDescriptor.isAbstract() == null ? false : entityDescriptor.isAbstract();
    final String subselect;
    final Identifier logicalTableName;
    final Table table;
    if (isTable) {
        final TableSource tableSource = (TableSource) tableSpecSource;
        if (StringHelper.isNotEmpty(tableSource.getExplicitTableName())) {
            logicalTableName = database.toIdentifier(tableSource.getExplicitTableName());
        } else {
            final ImplicitEntityNameSource implicitNamingSource = new ImplicitEntityNameSource() {

                @Override
                public EntityNaming getEntityNaming() {
                    return entitySource.getEntityNamingSource();
                }

                @Override
                public MetadataBuildingContext getBuildingContext() {
                    return mappingDocument;
                }
            };
            logicalTableName = mappingDocument.getBuildingOptions().getImplicitNamingStrategy().determinePrimaryTableName(implicitNamingSource);
        }
        if (denormalizedSuperTable == null) {
            table = namespace.createTable(logicalTableName, isAbstract);
        } else {
            table = namespace.createDenormalizedTable(logicalTableName, isAbstract, denormalizedSuperTable);
        }
    } else {
        final InLineViewSource inLineViewSource = (InLineViewSource) tableSpecSource;
        subselect = inLineViewSource.getSelectStatement();
        logicalTableName = database.toIdentifier(inLineViewSource.getLogicalName());
        if (denormalizedSuperTable == null) {
            table = new Table(namespace, subselect, isAbstract);
        } else {
            table = new DenormalizedTable(namespace, subselect, isAbstract, denormalizedSuperTable);
        }
        table.setName(logicalTableName.render());
    }
    EntityTableXref superEntityTableXref = null;
    if (entitySource.getSuperType() != null) {
        // noinspection SuspiciousMethodCalls
        final String superEntityName = ((EntitySource) entitySource.getSuperType()).getEntityNamingSource().getEntityName();
        superEntityTableXref = mappingDocument.getMetadataCollector().getEntityTableXref(superEntityName);
        if (superEntityTableXref == null) {
            throw new MappingException(String.format(Locale.ENGLISH, "Unable to locate entity table xref for entity [%s] super-type [%s]", entityDescriptor.getEntityName(), superEntityName), mappingDocument.getOrigin());
        }
    }
    mappingDocument.getMetadataCollector().addEntityTableXref(entitySource.getEntityNamingSource().getEntityName(), logicalTableName, table, superEntityTableXref);
    if (isTable) {
        final TableSource tableSource = (TableSource) tableSpecSource;
        table.setRowId(tableSource.getRowId());
        if (StringHelper.isNotEmpty(tableSource.getCheckConstraint())) {
            table.addCheckConstraint(tableSource.getCheckConstraint());
        }
    }
    table.setComment(tableSpecSource.getComment());
    mappingDocument.getMetadataCollector().addTableNameBinding(logicalTableName, table);
    return table;
}
Also used : Identifier(org.hibernate.boot.model.naming.Identifier) Table(org.hibernate.mapping.Table) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) TableSource(org.hibernate.boot.model.source.spi.TableSource) SecondaryTableSource(org.hibernate.boot.model.source.spi.SecondaryTableSource) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) EntityTableXref(org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref) ImplicitEntityNameSource(org.hibernate.boot.model.naming.ImplicitEntityNameSource) InLineViewSource(org.hibernate.boot.model.source.spi.InLineViewSource) Namespace(org.hibernate.boot.model.relational.Namespace) MappingException(org.hibernate.boot.MappingException)

Example 2 with EntityTableXref

use of org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref in project hibernate-orm by hibernate.

the class ModelBinder method bindAllEntityAttributes.

private void bindAllEntityAttributes(MappingDocument mappingDocument, EntitySource entitySource, PersistentClass entityDescriptor) {
    final EntityTableXref entityTableXref = mappingDocument.getMetadataCollector().getEntityTableXref(entityDescriptor.getEntityName());
    if (entityTableXref == null) {
        throw new AssertionFailure(String.format(Locale.ENGLISH, "Unable to locate EntityTableXref for entity [%s] : %s", entityDescriptor.getEntityName(), mappingDocument.getOrigin()));
    }
    // make sure we bind secondary tables first!
    for (SecondaryTableSource secondaryTableSource : entitySource.getSecondaryTableMap().values()) {
        final Join secondaryTableJoin = new Join();
        secondaryTableJoin.setPersistentClass(entityDescriptor);
        bindSecondaryTable(mappingDocument, secondaryTableSource, secondaryTableJoin, entityTableXref);
        entityDescriptor.addJoin(secondaryTableJoin);
    }
    for (AttributeSource attributeSource : entitySource.attributeSources()) {
        if (PluralAttributeSource.class.isInstance(attributeSource)) {
            // plural attribute
            final Property attribute = createPluralAttribute(mappingDocument, (PluralAttributeSource) attributeSource, entityDescriptor);
            entityDescriptor.addProperty(attribute);
        } else {
            // singular attribute
            if (SingularAttributeSourceBasic.class.isInstance(attributeSource)) {
                final SingularAttributeSourceBasic basicAttributeSource = (SingularAttributeSourceBasic) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, basicAttributeSource.getName(), basicAttributeSource);
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createBasicAttribute(mappingDocument, basicAttributeSource, new SimpleValue(mappingDocument, table), entityDescriptor.getClassName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, basicAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
                final SingularAttributeSourceEmbedded embeddedAttributeSource = (SingularAttributeSourceEmbedded) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, embeddedAttributeSource);
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createEmbeddedAttribute(mappingDocument, (SingularAttributeSourceEmbedded) attributeSource, new Component(mappingDocument, table, entityDescriptor), entityDescriptor.getClassName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, embeddedAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceManyToOne.class.isInstance(attributeSource)) {
                final SingularAttributeSourceManyToOne manyToOneAttributeSource = (SingularAttributeSourceManyToOne) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, manyToOneAttributeSource.getName(), manyToOneAttributeSource);
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createManyToOneAttribute(mappingDocument, manyToOneAttributeSource, new ManyToOne(mappingDocument, table), entityDescriptor.getClassName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, manyToOneAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceOneToOne.class.isInstance(attributeSource)) {
                final SingularAttributeSourceOneToOne oneToOneAttributeSource = (SingularAttributeSourceOneToOne) attributeSource;
                final Table table = entityDescriptor.getTable();
                final Property attribute = createOneToOneAttribute(mappingDocument, oneToOneAttributeSource, new OneToOne(mappingDocument, table, entityDescriptor), entityDescriptor.getClassName());
                entityDescriptor.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, oneToOneAttributeSource.getNaturalIdMutability());
            } else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
                final SingularAttributeSourceAny anyAttributeSource = (SingularAttributeSourceAny) attributeSource;
                final Identifier tableName = determineTable(mappingDocument, anyAttributeSource.getName(), anyAttributeSource.getKeySource().getRelationalValueSources());
                final AttributeContainer attributeContainer;
                final Table table;
                final Join secondaryTableJoin = entityTableXref.locateJoin(tableName);
                if (secondaryTableJoin == null) {
                    table = entityDescriptor.getTable();
                    attributeContainer = entityDescriptor;
                } else {
                    table = secondaryTableJoin.getTable();
                    attributeContainer = secondaryTableJoin;
                }
                final Property attribute = createAnyAssociationAttribute(mappingDocument, anyAttributeSource, new Any(mappingDocument, table), entityDescriptor.getEntityName());
                if (secondaryTableJoin != null) {
                    attribute.setOptional(secondaryTableJoin.isOptional());
                }
                attributeContainer.addProperty(attribute);
                handleNaturalIdBinding(mappingDocument, entityDescriptor, attribute, anyAttributeSource.getNaturalIdMutability());
            }
        }
    }
}
Also used : SingularAttributeSourceBasic(org.hibernate.boot.model.source.spi.SingularAttributeSourceBasic) AssertionFailure(org.hibernate.AssertionFailure) 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) Table(org.hibernate.mapping.Table) DenormalizedTable(org.hibernate.mapping.DenormalizedTable) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) Join(org.hibernate.mapping.Join) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) AttributeContainer(org.hibernate.mapping.AttributeContainer) SecondaryTableSource(org.hibernate.boot.model.source.spi.SecondaryTableSource) 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) OneToOne(org.hibernate.mapping.OneToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) Identifier(org.hibernate.boot.model.naming.Identifier) EntityTableXref(org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Example 3 with EntityTableXref

use of org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref in project hibernate-orm by hibernate.

the class AnnotationBinder method bindClass.

/**
 * Bind a class having JSR175 annotations. Subclasses <b>have to</b> be bound after its parent class.
 *
 * @param clazzToProcess entity to bind as {@code XClass} instance
 * @param inheritanceStatePerClass Meta data about the inheritance relationships for all mapped classes
 *
 * @throws MappingException in case there is a configuration error
 */
public static void bindClass(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, MetadataBuildingContext context) throws MappingException {
    // @Entity and @MappedSuperclass on the same class leads to a NPE down the road
    if (clazzToProcess.isAnnotationPresent(Entity.class) && clazzToProcess.isAnnotationPresent(MappedSuperclass.class)) {
        throw new AnnotationException("An entity cannot be annotated with both @Entity and @MappedSuperclass: " + clazzToProcess.getName());
    }
    // TODO: be more strict with secondarytable allowance (not for ids, not for secondary table join columns etc)
    InheritanceState inheritanceState = inheritanceStatePerClass.get(clazzToProcess);
    AnnotatedClassType classType = context.getMetadataCollector().getClassType(clazzToProcess);
    // Queries declared in MappedSuperclass should be usable in Subclasses
    if (AnnotatedClassType.EMBEDDABLE_SUPERCLASS.equals(classType)) {
        bindQueries(clazzToProcess, context);
        bindTypeDefs(clazzToProcess, context);
        bindFilterDefs(clazzToProcess, context);
    }
    if (!isEntityClassType(clazzToProcess, classType)) {
        return;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debugf("Binding entity from annotated class: %s", clazzToProcess.getName());
    }
    PersistentClass superEntity = getSuperEntity(clazzToProcess, inheritanceStatePerClass, context, inheritanceState);
    PersistentClass persistentClass = makePersistentClass(inheritanceState, superEntity, context);
    Entity entityAnn = clazzToProcess.getAnnotation(Entity.class);
    org.hibernate.annotations.Entity hibEntityAnn = clazzToProcess.getAnnotation(org.hibernate.annotations.Entity.class);
    EntityBinder entityBinder = new EntityBinder(entityAnn, hibEntityAnn, clazzToProcess, persistentClass, context);
    entityBinder.setInheritanceState(inheritanceState);
    bindQueries(clazzToProcess, context);
    bindFilterDefs(clazzToProcess, context);
    bindTypeDefs(clazzToProcess, context);
    bindFetchProfiles(clazzToProcess, context);
    BinderHelper.bindAnyMetaDefs(clazzToProcess, context);
    String schema = "";
    // might be no @Table annotation on the annotated class
    String table = "";
    String catalog = "";
    List<UniqueConstraintHolder> uniqueConstraints = new ArrayList<>();
    javax.persistence.Table tabAnn = null;
    if (clazzToProcess.isAnnotationPresent(javax.persistence.Table.class)) {
        tabAnn = clazzToProcess.getAnnotation(javax.persistence.Table.class);
        table = tabAnn.name();
        schema = tabAnn.schema();
        catalog = tabAnn.catalog();
        uniqueConstraints = TableBinder.buildUniqueConstraintHolders(tabAnn.uniqueConstraints());
    }
    Ejb3JoinColumn[] inheritanceJoinedColumns = makeInheritanceJoinColumns(clazzToProcess, context, inheritanceState, superEntity);
    final Ejb3DiscriminatorColumn discriminatorColumn;
    if (InheritanceType.SINGLE_TABLE.equals(inheritanceState.getType())) {
        discriminatorColumn = processSingleTableDiscriminatorProperties(clazzToProcess, context, inheritanceState, entityBinder);
    } else if (InheritanceType.JOINED.equals(inheritanceState.getType())) {
        discriminatorColumn = processJoinedDiscriminatorProperties(clazzToProcess, context, inheritanceState, entityBinder);
    } else {
        discriminatorColumn = null;
    }
    entityBinder.setProxy(clazzToProcess.getAnnotation(Proxy.class));
    entityBinder.setBatchSize(clazzToProcess.getAnnotation(BatchSize.class));
    entityBinder.setWhere(clazzToProcess.getAnnotation(Where.class));
    applyCacheSettings(entityBinder, clazzToProcess, context);
    bindFilters(clazzToProcess, entityBinder, context);
    entityBinder.bindEntity();
    if (inheritanceState.hasTable()) {
        Check checkAnn = clazzToProcess.getAnnotation(Check.class);
        String constraints = checkAnn == null ? null : checkAnn.constraints();
        EntityTableXref denormalizedTableXref = inheritanceState.hasDenormalizedTable() ? context.getMetadataCollector().getEntityTableXref(superEntity.getEntityName()) : null;
        entityBinder.bindTable(schema, catalog, table, uniqueConstraints, constraints, denormalizedTableXref);
    } else {
        if (clazzToProcess.isAnnotationPresent(Table.class)) {
            LOG.invalidTableAnnotation(clazzToProcess.getName());
        }
        if (inheritanceState.getType() == InheritanceType.SINGLE_TABLE) {
            // we at least need to properly set up the EntityTableXref
            entityBinder.bindTableForDiscriminatedSubclass(context.getMetadataCollector().getEntityTableXref(superEntity.getEntityName()));
        }
    }
    PropertyHolder propertyHolder = PropertyHolderBuilder.buildPropertyHolder(clazzToProcess, persistentClass, entityBinder, context, inheritanceStatePerClass);
    javax.persistence.SecondaryTable secTabAnn = clazzToProcess.getAnnotation(javax.persistence.SecondaryTable.class);
    javax.persistence.SecondaryTables secTabsAnn = clazzToProcess.getAnnotation(javax.persistence.SecondaryTables.class);
    entityBinder.firstLevelSecondaryTablesBinding(secTabAnn, secTabsAnn);
    OnDelete onDeleteAnn = clazzToProcess.getAnnotation(OnDelete.class);
    boolean onDeleteAppropriate = false;
    // todo : sucks that this is separate from RootClass distinction
    final boolean isInheritanceRoot = !inheritanceState.hasParents();
    final boolean hasSubclasses = inheritanceState.hasSiblings();
    if (InheritanceType.JOINED.equals(inheritanceState.getType())) {
        if (inheritanceState.hasParents()) {
            onDeleteAppropriate = true;
            final JoinedSubclass jsc = (JoinedSubclass) persistentClass;
            SimpleValue key = new DependantValue(context, jsc.getTable(), jsc.getIdentifier());
            jsc.setKey(key);
            ForeignKey fk = clazzToProcess.getAnnotation(ForeignKey.class);
            if (fk != null && !BinderHelper.isEmptyAnnotationValue(fk.name())) {
                key.setForeignKeyName(fk.name());
            } else {
                final PrimaryKeyJoinColumn pkJoinColumn = clazzToProcess.getAnnotation(PrimaryKeyJoinColumn.class);
                final PrimaryKeyJoinColumns pkJoinColumns = clazzToProcess.getAnnotation(PrimaryKeyJoinColumns.class);
                if (pkJoinColumns != null && pkJoinColumns.foreignKey().value() == ConstraintMode.NO_CONSTRAINT) {
                    // don't apply a constraint based on ConstraintMode
                    key.setForeignKeyName("none");
                } else if (pkJoinColumns != null && !StringHelper.isEmpty(pkJoinColumns.foreignKey().name())) {
                    key.setForeignKeyName(pkJoinColumns.foreignKey().name());
                } else if (pkJoinColumn != null && pkJoinColumn.foreignKey().value() == ConstraintMode.NO_CONSTRAINT) {
                    // don't apply a constraint based on ConstraintMode
                    key.setForeignKeyName("none");
                } else if (pkJoinColumn != null && !StringHelper.isEmpty(pkJoinColumn.foreignKey().name())) {
                    key.setForeignKeyName(pkJoinColumn.foreignKey().name());
                }
            }
            if (onDeleteAnn != null) {
                key.setCascadeDeleteEnabled(OnDeleteAction.CASCADE.equals(onDeleteAnn.action()));
            } else {
                key.setCascadeDeleteEnabled(false);
            }
            // we are never in a second pass at that stage, so queue it
            context.getMetadataCollector().addSecondPass(new JoinedSubclassFkSecondPass(jsc, inheritanceJoinedColumns, key, context));
            context.getMetadataCollector().addSecondPass(new CreateKeySecondPass(jsc));
        }
        if (isInheritanceRoot) {
            // (it is perfectly valid for joined subclasses to not have discriminators).
            if (discriminatorColumn != null) {
                // we have a discriminator column
                if (hasSubclasses || !discriminatorColumn.isImplicit()) {
                    bindDiscriminatorColumnToRootPersistentClass((RootClass) persistentClass, discriminatorColumn, entityBinder.getSecondaryTables(), propertyHolder, context);
                    // bind it again since the type might have changed
                    entityBinder.bindDiscriminatorValue();
                }
            }
        }
    } else if (InheritanceType.SINGLE_TABLE.equals(inheritanceState.getType())) {
        if (isInheritanceRoot) {
            if (hasSubclasses || !discriminatorColumn.isImplicit()) {
                bindDiscriminatorColumnToRootPersistentClass((RootClass) persistentClass, discriminatorColumn, entityBinder.getSecondaryTables(), propertyHolder, context);
                // bind it again since the type might have changed
                entityBinder.bindDiscriminatorValue();
            }
        }
    }
    if (onDeleteAnn != null && !onDeleteAppropriate) {
        LOG.invalidOnDeleteAnnotation(propertyHolder.getEntityName());
    }
    // try to find class level generators
    HashMap<String, IdentifierGeneratorDefinition> classGenerators = buildGenerators(clazzToProcess, context);
    // check properties
    final InheritanceState.ElementsToProcess elementsToProcess = inheritanceState.getElementsToProcess();
    inheritanceState.postProcess(persistentClass, entityBinder);
    final boolean subclassAndSingleTableStrategy = inheritanceState.getType() == InheritanceType.SINGLE_TABLE && inheritanceState.hasParents();
    Set<String> idPropertiesIfIdClass = new HashSet<>();
    boolean isIdClass = mapAsIdClass(inheritanceStatePerClass, inheritanceState, persistentClass, entityBinder, propertyHolder, elementsToProcess, idPropertiesIfIdClass, context);
    if (!isIdClass) {
        entityBinder.setWrapIdsInEmbeddedComponents(elementsToProcess.getIdPropertyCount() > 1);
    }
    processIdPropertiesIfNotAlready(inheritanceStatePerClass, context, persistentClass, entityBinder, propertyHolder, classGenerators, elementsToProcess, subclassAndSingleTableStrategy, idPropertiesIfIdClass);
    if (!inheritanceState.hasParents()) {
        final RootClass rootClass = (RootClass) persistentClass;
        context.getMetadataCollector().addSecondPass(new CreateKeySecondPass(rootClass));
    } else {
        superEntity.addSubclass((Subclass) persistentClass);
    }
    context.getMetadataCollector().addEntityBinding(persistentClass);
    // Process secondary tables and complementary definitions (ie o.h.a.Table)
    context.getMetadataCollector().addSecondPass(new SecondaryTableSecondPass(entityBinder, propertyHolder, clazzToProcess));
    // add process complementary Table definition (index & all)
    entityBinder.processComplementaryTableDefinitions(clazzToProcess.getAnnotation(org.hibernate.annotations.Table.class));
    entityBinder.processComplementaryTableDefinitions(clazzToProcess.getAnnotation(org.hibernate.annotations.Tables.class));
    entityBinder.processComplementaryTableDefinitions(tabAnn);
}
Also used : Entity(javax.persistence.Entity) ArrayList(java.util.ArrayList) Check(org.hibernate.annotations.Check) Proxy(org.hibernate.annotations.Proxy) PrimaryKeyJoinColumn(javax.persistence.PrimaryKeyJoinColumn) Table(javax.persistence.Table) PrimaryKeyJoinColumns(javax.persistence.PrimaryKeyJoinColumns) AnnotationException(org.hibernate.AnnotationException) JoinedSubclass(org.hibernate.mapping.JoinedSubclass) PersistentClass(org.hibernate.mapping.PersistentClass) HashSet(java.util.HashSet) RootClass(org.hibernate.mapping.RootClass) BatchSize(org.hibernate.annotations.BatchSize) Table(javax.persistence.Table) CollectionTable(javax.persistence.CollectionTable) JoinTable(javax.persistence.JoinTable) DependantValue(org.hibernate.mapping.DependantValue) ForeignKey(org.hibernate.annotations.ForeignKey) SimpleValue(org.hibernate.mapping.SimpleValue) MappedSuperclass(javax.persistence.MappedSuperclass) EntityTableXref(org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref) IdentifierGeneratorDefinition(org.hibernate.boot.model.IdentifierGeneratorDefinition) EntityBinder(org.hibernate.cfg.annotations.EntityBinder) Where(org.hibernate.annotations.Where) OnDelete(org.hibernate.annotations.OnDelete)

Example 4 with EntityTableXref

use of org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref in project hibernate-orm by hibernate.

the class ModelBinder method bindDiscriminatorSubclassEntity.

private void bindDiscriminatorSubclassEntity(SubclassEntitySourceImpl entitySource, SingleTableSubclass entityDescriptor) {
    bindBasicEntityValues(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
    final String superEntityName = ((EntitySource) entitySource.getSuperType()).getEntityNamingSource().getEntityName();
    final EntityTableXref superEntityTableXref = entitySource.getLocalMetadataBuildingContext().getMetadataCollector().getEntityTableXref(superEntityName);
    if (superEntityTableXref == null) {
        throw new MappingException(String.format(Locale.ENGLISH, "Unable to locate entity table xref for entity [%s] super-type [%s]", entityDescriptor.getEntityName(), superEntityName), entitySource.origin());
    }
    entitySource.getLocalMetadataBuildingContext().getMetadataCollector().addEntityTableXref(entitySource.getEntityNamingSource().getEntityName(), database.toIdentifier(entitySource.getLocalMetadataBuildingContext().getMetadataCollector().getLogicalTableName(entityDescriptor.getTable())), entityDescriptor.getTable(), superEntityTableXref);
    bindAllEntityAttributes(entitySource.sourceMappingDocument(), entitySource, entityDescriptor);
    bindDiscriminatorSubclassEntities(entitySource, entityDescriptor);
}
Also used : EntityTableXref(org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref) MappingException(org.hibernate.boot.MappingException)

Aggregations

EntityTableXref (org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref)4 MappingException (org.hibernate.boot.MappingException)2 Identifier (org.hibernate.boot.model.naming.Identifier)2 SecondaryTableSource (org.hibernate.boot.model.source.spi.SecondaryTableSource)2 DenormalizedTable (org.hibernate.mapping.DenormalizedTable)2 SimpleValue (org.hibernate.mapping.SimpleValue)2 Table (org.hibernate.mapping.Table)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CollectionTable (javax.persistence.CollectionTable)1 Entity (javax.persistence.Entity)1 JoinTable (javax.persistence.JoinTable)1 MappedSuperclass (javax.persistence.MappedSuperclass)1 PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)1 PrimaryKeyJoinColumns (javax.persistence.PrimaryKeyJoinColumns)1 Table (javax.persistence.Table)1 AnnotationException (org.hibernate.AnnotationException)1 AssertionFailure (org.hibernate.AssertionFailure)1 BatchSize (org.hibernate.annotations.BatchSize)1 Check (org.hibernate.annotations.Check)1