Search in sources :

Example 1 with MappedSuperclass

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

the class JoinedSubclassEntityPersister method processPersistentClassHierarchy.

private Set<String> processPersistentClassHierarchy(PersistentClass persistentClass, boolean isBase, SessionFactoryImplementor factory, String[][] mapping) {
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // collect all the class names that indicate that the "main table" of the given PersistentClass should be
    // included when one of the collected class names is used in TREAT
    final Set<String> classNames = new HashSet<String>();
    final Iterator itr = persistentClass.getDirectSubclasses();
    while (itr.hasNext()) {
        final Subclass subclass = (Subclass) itr.next();
        final Set<String> subclassSubclassNames = processPersistentClassHierarchy(subclass, false, factory, mapping);
        classNames.addAll(subclassSubclassNames);
    }
    classNames.add(persistentClass.getEntityName());
    if (!isBase) {
        MappedSuperclass msc = persistentClass.getSuperMappedSuperclass();
        while (msc != null) {
            classNames.add(msc.getMappedClass().getName());
            msc = msc.getSuperMappedSuperclass();
        }
        associateSubclassNamesToSubclassTableIndexes(persistentClass, classNames, mapping, factory);
    }
    return classNames;
}
Also used : Subclass(org.hibernate.mapping.Subclass) MappedSuperclass(org.hibernate.mapping.MappedSuperclass) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 2 with MappedSuperclass

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

the class MetamodelImpl method buildMappedSuperclassType.

// TODO remove / reduce @SW scope
@SuppressWarnings("unchecked")
private static MappedSuperclassTypeImpl<?> buildMappedSuperclassType(MappedSuperclass mappedSuperclass, MetadataContext context) {
    final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
    AbstractIdentifiableType<?> superType = superMappedSuperclass == null ? null : locateOrBuildMappedsuperclassType(superMappedSuperclass, context);
    // no mappedSuperclass, check for a super entity
    if (superType == null) {
        final PersistentClass superPersistentClass = mappedSuperclass.getSuperPersistentClass();
        superType = superPersistentClass == null ? null : locateOrBuildEntityType(superPersistentClass, context);
    }
    final Class javaType = mappedSuperclass.getMappedClass();
    MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(javaType, mappedSuperclass, superType);
    context.registerMappedSuperclassType(mappedSuperclass, mappedSuperclassType);
    return mappedSuperclassType;
}
Also used : MappedSuperclass(org.hibernate.mapping.MappedSuperclass) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 3 with MappedSuperclass

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

the class MetamodelImpl method handleUnusedMappedSuperclasses.

private static void handleUnusedMappedSuperclasses(MetadataContext context) {
    final Set<MappedSuperclass> unusedMappedSuperclasses = context.getUnusedMappedSuperclasses();
    if (!unusedMappedSuperclasses.isEmpty()) {
        for (MappedSuperclass mappedSuperclass : unusedMappedSuperclasses) {
            log.unusedMappedSuperclass(mappedSuperclass.getMappedClass().getName());
            locateOrBuildMappedsuperclassType(mappedSuperclass, context);
        }
    }
}
Also used : MappedSuperclass(org.hibernate.mapping.MappedSuperclass)

Example 4 with MappedSuperclass

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

the class MetadataContext method wrapUp.

@SuppressWarnings({ "unchecked" })
public void wrapUp() {
    final boolean traceEnabled = LOG.isTraceEnabled();
    if (traceEnabled) {
        LOG.trace("Wrapping up metadata context...");
    }
    boolean staticMetamodelScanEnabled = JpaStaticMetaModelPopulationSetting.determineJpaMetaModelPopulationSetting(sessionFactory.getProperties()) != JpaStaticMetaModelPopulationSetting.DISABLED;
    // we need to process types from superclasses to subclasses
    for (Object mapping : orderedMappings) {
        if (PersistentClass.class.isAssignableFrom(mapping.getClass())) {
            @SuppressWarnings("unchecked") final PersistentClass safeMapping = (PersistentClass) mapping;
            if (traceEnabled) {
                LOG.trace("Starting entity [" + safeMapping.getEntityName() + ']');
            }
            try {
                final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get(safeMapping);
                applyIdMetadata(safeMapping, jpa2Mapping);
                applyVersionAttribute(safeMapping, jpa2Mapping);
                Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator();
                while (properties.hasNext()) {
                    final Property property = properties.next();
                    if (property.getValue() == safeMapping.getIdentifierMapper()) {
                        // #buildIdClassAttributes
                        continue;
                    }
                    if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
                        // skip the version property, it was already handled previously.
                        continue;
                    }
                    final Attribute attribute = attributeFactory.buildAttribute(jpa2Mapping, property);
                    if (attribute != null) {
                        jpa2Mapping.getBuilder().addAttribute(attribute);
                    }
                }
                jpa2Mapping.lock();
                if (staticMetamodelScanEnabled) {
                    populateStaticMetamodel(jpa2Mapping);
                }
            } finally {
                if (traceEnabled) {
                    LOG.trace("Completed entity [" + safeMapping.getEntityName() + ']');
                }
            }
        } else if (MappedSuperclass.class.isAssignableFrom(mapping.getClass())) {
            @SuppressWarnings("unchecked") final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
            if (traceEnabled) {
                LOG.trace("Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
            }
            try {
                final MappedSuperclassTypeImpl<?> jpa2Mapping = mappedSuperclassByMappedSuperclassMapping.get(safeMapping);
                applyIdMetadata(safeMapping, jpa2Mapping);
                applyVersionAttribute(safeMapping, jpa2Mapping);
                Iterator<Property> properties = safeMapping.getDeclaredPropertyIterator();
                while (properties.hasNext()) {
                    final Property property = properties.next();
                    if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
                        // skip the version property, it was already handled previously.
                        continue;
                    }
                    final Attribute attribute = attributeFactory.buildAttribute(jpa2Mapping, property);
                    if (attribute != null) {
                        jpa2Mapping.getBuilder().addAttribute(attribute);
                    }
                }
                jpa2Mapping.lock();
                if (staticMetamodelScanEnabled) {
                    populateStaticMetamodel(jpa2Mapping);
                }
            } finally {
                if (traceEnabled) {
                    LOG.trace("Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
                }
            }
        } else {
            throw new AssertionFailure("Unexpected mapping type: " + mapping.getClass());
        }
    }
    if (staticMetamodelScanEnabled) {
        for (EmbeddableTypeImpl embeddable : embeddables.values()) {
            populateStaticMetamodel(embeddable);
        }
    }
}
Also used : AssertionFailure(org.hibernate.annotations.common.AssertionFailure) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) MappedSuperclass(org.hibernate.mapping.MappedSuperclass) Iterator(java.util.Iterator) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 5 with MappedSuperclass

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

the class ClassPropertyHolder method addPropertyToMappedSuperclass.

private void addPropertyToMappedSuperclass(Property prop, XClass declaringClass) {
    final Class type = getContext().getBootstrapContext().getReflectionManager().toClass(declaringClass);
    MappedSuperclass superclass = getContext().getMetadataCollector().getMappedSuperclass(type);
    superclass.addDeclaredProperty(prop);
}
Also used : MappedSuperclass(org.hibernate.mapping.MappedSuperclass) XClass(org.hibernate.annotations.common.reflection.XClass) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

MappedSuperclass (org.hibernate.mapping.MappedSuperclass)6 PersistentClass (org.hibernate.mapping.PersistentClass)4 Iterator (java.util.Iterator)2 RootClass (org.hibernate.mapping.RootClass)2 HashSet (java.util.HashSet)1 Attribute (javax.persistence.metamodel.Attribute)1 SingularAttribute (javax.persistence.metamodel.SingularAttribute)1 AssertionFailure (org.hibernate.annotations.common.AssertionFailure)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 Property (org.hibernate.mapping.Property)1 Subclass (org.hibernate.mapping.Subclass)1