public boolean canProcessImmediately() { // We can process the FK immediately if it is a reference to the associated // entity's PK. // // There is an assumption here that the columns making up the FK have been bound. // We assume the caller checks that final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector() .getEntityBinding( referencedEntityName ); return referencedEntityBinding != null && referencedEntityAttributeName != null; } }
@Override public PersistentClass findEntityBinding(String entityName, String clazz) { return getMetadataCollector().getEntityBinding( determineEntityName( entityName, clazz ) ); }
public boolean canProcessImmediately() { if ( allColumnsNamed ) { return true; } final PersistentClass referencedEntityBinding = mappingDocument.getMetadataCollector() .getEntityBinding( referencedEntityName ); if ( referencedEntityBinding == null ) { return false; } // for implicit naming, we can do it immediately if the associated entity // is bound and the reference is to its PK. For property-refs, we'd have to // be *sure* that the column(s) for the referenced property is fully bound // and we just cannot know that in today's model return manyToOneSource.getReferencedEntityAttributeName() == null; }
@Override public boolean isInPrimaryKey() { if ( entityClassName == null ) return false; final PersistentClass persistentClass = buildingContext.getMetadataCollector().getEntityBinding( entityClassName ); Property property = persistentClass.getIdentifierProperty(); if ( path == null ) { return false; } else if ( property != null) { //try explicit identifier property return path.startsWith( property.getName() + "." ); } else { //try the embedded property //embedded property starts their path with 'id.' See PropertyPreloadedData( ) use when idClass != null in AnnotationSourceProcessor if ( path.startsWith( "id." ) ) { KeyValue valueIdentifier = persistentClass.getIdentifier(); String localPath = path.substring( 3 ); if ( valueIdentifier instanceof Component ) { Iterator it = ( (Component) valueIdentifier ).getPropertyIterator(); while ( it.hasNext() ) { Property idProperty = (Property) it.next(); if ( localPath.startsWith( idProperty.getName() ) ) return true; } } } } return false; }
@Override public void process(InFlightMetadataCollector metadataCollector) { final PersistentClass clazz = metadataCollector.getEntityBinding( referencedClass ); if ( clazz == null ) { throw new MappingException( "property-ref to unmapped class: " + referencedClass ); } final Property prop = clazz.getReferencedProperty( propertyName ); if ( unique ) { ( (SimpleValue) prop.getValue() ).setAlternateUniqueKey( true ); } } }
); PersistentClass entityBinding = metadataCollector.getEntityBinding( referencedEntityName ); if ( entityBinding == null ) { throw new MappingException(
public void doSecondPass(Map persistentClasses) throws MappingException { org.hibernate.mapping.FetchProfile profile = buildingContext.getMetadataCollector().getFetchProfile( fetchProfileName ); if ( profile != null ) { if ( profile.getSource() != MetadataSource.ANNOTATIONS ) { return; } } else { profile = new org.hibernate.mapping.FetchProfile( fetchProfileName, MetadataSource.ANNOTATIONS ); buildingContext.getMetadataCollector().addFetchProfile( profile ); } PersistentClass clazz = buildingContext.getMetadataCollector().getEntityBinding( fetch.entity().getName() ); // throws MappingException in case the property does not exist clazz.getProperty( fetch.association() ); profile.addFetch( fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase(Locale.ROOT) ); } }
.getEntityBinding( mappedByEntityName ); final Property mappedByProperty = mappedByEntityBinding.getProperty( mappedByPropertyName ); final SimpleValue value = (SimpleValue) mappedByProperty.getValue();
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; }
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 ); } }
public static NativeSQLQueryRootReturn extractReturnDescription( JaxbHbmNativeQueryReturnType rtnSource, HbmLocalMetadataBuildingContext context, int queryReturnPosition) { String alias = rtnSource.getAlias(); if ( StringHelper.isEmpty( alias ) ) { // hack-around as sqlquery impl depend on having a key. alias = "alias_" + queryReturnPosition; } final String entityName = context.determineEntityName( rtnSource.getEntityName(), rtnSource.getClazz() ); final PersistentClass pc = context.getMetadataCollector().getEntityBinding( entityName ); return new NativeSQLQueryRootReturn( alias, entityName, extractPropertyResults( alias, rtnSource, pc, context ), rtnSource.getLockMode() ); }
boolean isUnique, String sourceElementSynopsis) { PersistentClass entityBinding = mappingDocument.getMetadataCollector().getEntityBinding( referencedEntityName ); if ( entityBinding == null ) {
.getEntityBinding( referencedEntityName );
private void createIndexBackRef( MappingDocument mappingDocument, IndexedPluralAttributeSource pluralAttributeSource, IndexedCollection collectionBinding) { if ( collectionBinding.isOneToMany() && !collectionBinding.getKey().isNullable() && !collectionBinding.isInverse() ) { final String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); final PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref(); ib.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( collectionBinding.getRole() ); ib.setEntityName( collectionBinding.getOwner().getEntityName() ); ib.setValue( collectionBinding.getIndex() ); referenced.addProperty( ib ); } }
@Override protected void createBackReferences() { super.createBackReferences(); boolean indexIsFormula = false; Iterator itr = getCollectionBinding().getIndex().getColumnIterator(); while ( itr.hasNext() ) { if ( ( (Selectable) itr.next() ).isFormula() ) { indexIsFormula = true; } } if ( getCollectionBinding().isOneToMany() && !getCollectionBinding().getKey().isNullable() && !getCollectionBinding().isInverse() && !indexIsFormula ) { final String entityName = ( (OneToMany) getCollectionBinding().getElement() ).getReferencedEntityName(); final PersistentClass referenced = getMappingDocument().getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref(); ib.setName( '_' + getCollectionBinding().getOwnerEntityName() + "." + getPluralAttributeSource().getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( getCollectionBinding().getRole() ); ib.setEntityName( getCollectionBinding().getOwner().getEntityName() ); ib.setValue( getCollectionBinding().getIndex() ); referenced.addProperty( ib ); } } }
PersistentClass referencedPc = context.getMetadataCollector().getEntityBinding( toOne.getReferencedEntityName() ); if ( toOne.getReferencedPropertyName() != null ) { try {
protected void createBackReferences() { if ( collectionBinding.isOneToMany() && !collectionBinding.isInverse() && !collectionBinding.getKey().isNullable() ) { // for non-inverse one-to-many, with a not-null fk, add a backref! String entityName = ( (OneToMany) collectionBinding.getElement() ).getReferencedEntityName(); PersistentClass referenced = mappingDocument.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref(); prop.setName( '_' + collectionBinding.getOwnerEntityName() + "." + pluralAttributeSource.getName() + "Backref" ); prop.setUpdateable( false ); prop.setSelectable( false ); prop.setCollectionRole( collectionBinding.getRole() ); prop.setEntityName( collectionBinding.getOwner().getEntityName() ); prop.setValue( collectionBinding.getKey() ); referenced.addProperty( prop ); log.debugf( "Added virtual backref property [%s] : %s", prop.getName(), pluralAttributeSource.getAttributeRole().getFullPath() ); } }
PersistentClass referenced = buildingContext.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref(); prop.setName( '_' + fkJoinColumns[0].getPropertyName() + '_' + fkJoinColumns[0].getLogicalColumnName() + "Backref" );
.getEntityBinding( elementSource.getReferencedEntityName() ); if ( persistentClass == null ) { throw new MappingException(
if ( list.isOneToMany() && !list.getKey().isNullable() && !list.isInverse() ) { String entityName = ( (OneToMany) list.getElement() ).getReferencedEntityName(); PersistentClass referenced = buildingContext.getMetadataCollector().getEntityBinding( entityName ); IndexBackref ib = new IndexBackref(); ib.setName( '_' + propertyName + "IndexBackref" );