); for ( XClass clazz : orderedClasses ) { InheritanceState superclassState = InheritanceState.getSuperclassInheritanceState( clazz, inheritanceStatePerClass ); InheritanceState state = new InheritanceState( clazz, inheritanceStatePerClass, buildingContext ); if ( superclassState != null ) { superclassState.setHasSiblings( true ); InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass ); state.setHasParents( superEntityState != null ); final boolean nonDefault = state.getType() != null && !InheritanceType.SINGLE_TABLE .equals( state.getType() ); if ( superclassState.getType() != null ) { final boolean mixingStrategy = state.getType() != null && !state.getType() .equals( superclassState.getType() ); if ( nonDefault && mixingStrategy ) { LOG.invalidSubStrategy( clazz.getName() ); state.setType( superclassState.getType() );
public InheritanceState( XClass clazz, Map<XClass, InheritanceState> inheritanceStatePerClass, MetadataBuildingContext buildingContext) { this.setClazz( clazz ); this.buildingContext = buildingContext; this.inheritanceStatePerClass = inheritanceStatePerClass; extractInheritanceType(); }
void postProcess(PersistentClass persistenceClass, EntityBinder entityBinder) { //make sure we run elements to process getElementsToProcess(); addMappedSuperClassInMetadata( persistenceClass ); entityBinder.setPropertyAccessType( accessType ); }
public XClass getClassWithIdClass(boolean evenIfSubclass) { if ( !evenIfSubclass && hasParents() ) { return null; } if ( clazz.isAnnotationPresent( IdClass.class ) ) { return clazz; } else { InheritanceState state = InheritanceState.getSuperclassInheritanceState( clazz, inheritanceStatePerClass ); if ( state != null ) { return state.getClassWithIdClass( true ); } else { return null; } } }
if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) { discriminatorColumn = processSingleTableDiscriminatorProperties( clazzToProcess, else if ( InheritanceType.JOINED.equals( inheritanceState.getType() ) ) { discriminatorColumn = processJoinedDiscriminatorProperties( clazzToProcess, if ( inheritanceState.hasTable() ) { Check checkAnn = clazzToProcess.getAnnotation( Check.class ); String constraints = checkAnn == null EntityTableXref denormalizedTableXref = inheritanceState.hasDenormalizedTable() ? context.getMetadataCollector().getEntityTableXref( superEntity.getEntityName() ) : null; if ( inheritanceState.getType() == InheritanceType.SINGLE_TABLE ) { 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; else if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) { if ( isInheritanceRoot ) { if ( hasSubclasses || !discriminatorColumn.isImplicit() ) {
public ElementsToProcess getElementsToProcess() { if ( elementsToProcess == null ) { InheritanceState inheritanceState = inheritanceStatePerClass.get( clazz ); assert !inheritanceState.isEmbeddableSuperclass(); getMappedSuperclassesTillNextEntityOrdered(); accessType = determineDefaultAccessType(); ArrayList<PropertyData> elements = new ArrayList<PropertyData>(); int idPropertyCount = 0; for ( XClass classToProcessForMappedSuperclass : classesToProcessForMappedSuperclass ) { PropertyContainer propertyContainer = new PropertyContainer( classToProcessForMappedSuperclass, clazz, accessType ); int currentIdPropertyCount = AnnotationBinder.addElementsOfClass( elements, propertyContainer, buildingContext ); idPropertyCount += currentIdPropertyCount; } if ( idPropertyCount == 0 && !inheritanceState.hasParents() ) { throw new AnnotationException( "No identifier specified for entity: " + clazz.getName() ); } elements.trimToSize(); elementsToProcess = new ElementsToProcess( elements, idPropertyCount ); } return elementsToProcess; }
private void extractInheritanceType() { XAnnotatedElement element = getClazz(); Inheritance inhAnn = element.getAnnotation( Inheritance.class ); MappedSuperclass mappedSuperClass = element.getAnnotation( MappedSuperclass.class ); if ( mappedSuperClass != null ) { setEmbeddableSuperclass( true ); setType( inhAnn == null ? null : inhAnn.strategy() ); } else { setType( inhAnn == null ? InheritanceType.SINGLE_TABLE : inhAnn.strategy() ); } }
private static PersistentClass getSuperEntity( XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, MetadataBuildingContext context, InheritanceState inheritanceState) { InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazzToProcess, inheritanceStatePerClass ); PersistentClass superEntity = superEntityState != null ? context.getMetadataCollector().getEntityBinding( superEntityState.getClazz().getName() ) : null; if ( superEntity == null ) { //check if superclass is not a potential persistent class if ( inheritanceState.hasParents() ) { throw new AssertionFailure( "Subclass has to be binded after it's mother class: " + superEntityState.getClazz().getName() ); } } return superEntity; }
public Boolean hasIdClassOrEmbeddedId() { if ( hasIdClassOrEmbeddedId == null ) { hasIdClassOrEmbeddedId = false; if ( getClassWithIdClass( true ) != null ) { hasIdClassOrEmbeddedId = true; } else { final ElementsToProcess process = getElementsToProcess(); for ( PropertyData property : process.getElements() ) { if ( property.getProperty().isAnnotationPresent( EmbeddedId.class ) ) { hasIdClassOrEmbeddedId = true; break; } } } } return hasIdClassOrEmbeddedId; }
private void addMappedSuperClassInMetadata(PersistentClass persistentClass) { //add @MappedSuperclass in the metadata // classes from 0 to n-1 are @MappedSuperclass and should be linked org.hibernate.mapping.MappedSuperclass mappedSuperclass = null; final InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazz, inheritanceStatePerClass ); PersistentClass superEntity = superEntityState != null ? buildingContext.getMetadataCollector().getEntityBinding( superEntityState.getClazz().getName() ) : null; final int lastMappedSuperclass = classesToProcessForMappedSuperclass.size() - 1; for ( int index = 0; index < lastMappedSuperclass; index++ ) { org.hibernate.mapping.MappedSuperclass parentSuperclass = mappedSuperclass; final Class<?> type = buildingContext.getBootstrapContext().getReflectionManager() .toClass( classesToProcessForMappedSuperclass.get( index ) ); //add MAppedSuperclass if not already there mappedSuperclass = buildingContext.getMetadataCollector().getMappedSuperclass( type ); if ( mappedSuperclass == null ) { mappedSuperclass = new org.hibernate.mapping.MappedSuperclass( parentSuperclass, superEntity ); mappedSuperclass.setMappedClass( type ); buildingContext.getMetadataCollector().addMappedSuperclass( type, mappedSuperclass ); } } if ( mappedSuperclass != null ) { persistentClass.setSuperMappedSuperclass( mappedSuperclass ); } }
if ( log.isInfoEnabled() ) log.info( "Binding entity from annotated class: " + clazzToProcess.getName() ); InheritanceState superEntityState = InheritanceState.getSuperEntityInheritanceState( clazzToProcess, inheritanceStatePerClass, mappings.getReflectionManager() ); if ( inheritanceState.hasTable() ) { Check checkAnn = annotatedClass.getAnnotation( Check.class ); String constraints = checkAnn == null ? null : checkAnn.constraints(); entityBinder.bindTable( schema, catalog, table, uniqueConstraints, constraints, inheritanceState.hasDenormalizedTable() ? superEntity.getTable() : null ); break; state = InheritanceState.getSuperclassInheritanceState( current, inheritanceStatePerClass, mappings.getReflectionManager() );
return false; //while it is likely a user error, let's consider it is something that might happen final XClass associatedClassWithIdClass = state.getClassWithIdClass( true ); if ( associatedClassWithIdClass == null ) {
); for ( XClass clazz : orderedClasses ) { InheritanceState superclassState = InheritanceState.getSuperclassInheritanceState( clazz, inheritanceStatePerClass, reflectionManager ); InheritanceState state = new InheritanceState( clazz ); if ( superclassState != null ) { InheritanceState superEntityState = InheritanceState.getSuperEntityInheritanceState( clazz, inheritanceStatePerClass, reflectionManager
@Override public String getEntityName() { return inheritanceState.getClazz().getName(); }
public InheritanceState(XClass clazz) { this.clazz = clazz; extractInheritanceType(); }
Ejb3DiscriminatorColumn discriminatorColumn = null; String discrimValue = null; if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.getType() ) ) { javax.persistence.DiscriminatorColumn discAnn = clazzToProcess.getAnnotation( javax.persistence.DiscriminatorColumn.class org.hibernate.annotations.DiscriminatorFormula.class ); if ( !inheritanceState.hasParents() ) { discriminatorColumn = Ejb3DiscriminatorColumn.buildDiscriminatorColumn( discriminatorType, discAnn, discFormulaAnn, mappings ); if ( discAnn != null && inheritanceState.hasParents() ) { log.warn( "Discriminator column has to be defined in the root entity, it will be ignored in subclass: {}", if ( !inheritanceState.hasParents() ) { bindFilters( clazzToProcess, entityBinder, mappings ); if ( inheritanceState.hasTable() ) { Check checkAnn = clazzToProcess.getAnnotation( Check.class ); String constraints = checkAnn == null ? entityBinder.bindTable( schema, catalog, table, uniqueConstraints, constraints, inheritanceState.hasDenormalizedTable() ? superEntity.getTable() : null
public ElementsToProcess getElementsToProcess() { if (elementsToProcess == null) { InheritanceState inheritanceState = inheritanceStatePerClass.get( clazz ); assert !inheritanceState.isEmbeddableSuperclass(); getMappedSuperclassesTillNextEntityOrdered(); accessType = determineDefaultAccessType( ); List<PropertyData> elements = new ArrayList<PropertyData>(); int deep = classesToProcessForMappedSuperclass.size(); int idPropertyCount = 0; for ( int index = 0; index < deep; index++ ) { PropertyContainer propertyContainer = new PropertyContainer( classesToProcessForMappedSuperclass.get( index ), clazz ); int currentIdPropertyCount = AnnotationBinder.addElementsOfClass( elements, accessType, propertyContainer, mappings ); idPropertyCount += currentIdPropertyCount; } if ( idPropertyCount == 0 && !inheritanceState.hasParents() ) { throw new AnnotationException( "No identifier specified for entity: " + clazz.getName() ); } elementsToProcess = new ElementsToProcess( elements, idPropertyCount); } return elementsToProcess; }
public XClass getClassWithIdClass(boolean evenIfSubclass) { if ( !evenIfSubclass && hasParents() ) { return null; } if ( clazz.isAnnotationPresent( IdClass.class ) ) { return clazz; } else { InheritanceState state = InheritanceState.getSuperclassInheritanceState( clazz, inheritanceStatePerClass ); if (state != null){ return state.getClassWithIdClass(true); } else { return null; } } }
private void extractInheritanceType() { XAnnotatedElement element = getClazz(); Inheritance inhAnn = element.getAnnotation( Inheritance.class ); MappedSuperclass mappedSuperClass = element.getAnnotation( MappedSuperclass.class ); if ( mappedSuperClass != null ) { setEmbeddableSuperclass( true ); setType( inhAnn == null ? null : inhAnn.strategy() ); } else { setType( inhAnn == null ? InheritanceType.SINGLE_TABLE : inhAnn.strategy() ); } }
private static PersistentClass getSuperEntity(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, ExtendedMappings mappings, InheritanceState inheritanceState) { InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity( clazzToProcess, inheritanceStatePerClass ); PersistentClass superEntity = superEntityState != null ? mappings.getClass( superEntityState.getClazz().getName() ) : null; if ( superEntity == null ) { //check if superclass is not a potential persistent class if ( inheritanceState.hasParents() ) { throw new AssertionFailure( "Subclass has to be binded after it's mother class: " + superEntityState.getClazz().getName() ); } } return superEntity; }