public PersistentClass getPersistentClass() { return collection.getOwner(); }
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() ); } }
/** * @deprecated User {@link Component#Component(MetadataBuildingContext, Collection)} instead. */ @Deprecated public Component(MetadataImplementor metadata, Collection collection) throws MappingException { this( metadata, collection.getCollectionTable(), collection.getOwner() ); }
@Override public boolean isVersioned() { return collectionDescriptor.getOwner().isVersioned(); }
public String getEntityName() { return collection.getOwner().getEntityName(); }
public Component(MetadataBuildingContext metadata, Collection collection) throws MappingException { this( metadata, collection.getCollectionTable(), collection.getOwner() ); }
@Override public Identifier getOwningPhysicalTableName() { return collectionBinding.getOwner().getTable().getNameIdentifier(); }
private void createForeignKeys() throws MappingException { // if ( !isInverse() ) { // for inverse collections, let the "other end" handle it if ( referencedPropertyName == null ) { getElement().createForeignKey(); key.createForeignKeyOfEntity( getOwner().getEntityName() ); } // } }
@Override public Comparator getOwnerVersionComparator() { if ( !isVersioned() ) { return null; } return ( (VersionType) collectionDescriptor.getOwner().getVersion().getType() ).getComparator(); }
private static void bindCollectionSecondPass( Collection collValue, PersistentClass collectionEntity, Ejb3JoinColumn[] joinColumns, boolean cascadeDeleteEnabled, XProperty property, PropertyHolder propertyHolder, MetadataBuildingContext buildingContext) { try { BinderHelper.createSyntheticPropertyReference( joinColumns, collValue.getOwner(), collectionEntity, collValue, false, buildingContext ); } catch (AnnotationException ex) { throw new AnnotationException( "Unable to map collection " + collValue.getOwner().getClassName() + "." + property.getName(), ex ); } SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, propertyHolder, buildingContext ); if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) { joinColumns[0].setJPA2ElementCollection( true ); } TableBinder.bindFk( collValue.getOwner(), collectionEntity, joinColumns, key, false, buildingContext ); }
protected void checkDefaultJoinColumnName( Class<?> ownerEntityClass, String ownerCollectionPropertyName, String ownerForeignKeyNameExpected) { final org.hibernate.mapping.Collection ownerCollection = metadata().getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); // The default owner join column can only be computed if it has a PK with 1 column. assertEquals ( 1, ownerCollection.getOwner().getKey().getColumnSpan() ); assertEquals( ownerForeignKeyNameExpected, ownerCollection.getKey().getColumnIterator().next().getText() ); boolean hasOwnerFK = false; for ( Iterator it=ownerCollection.getCollectionTable().getForeignKeyIterator(); it.hasNext(); ) { final ForeignKey fk = (ForeignKey) it.next(); assertSame( ownerCollection.getCollectionTable(), fk.getTable() ); if ( fk.getColumnSpan() > 1 ) { continue; } if ( fk.getColumn( 0 ).getText().equals( ownerForeignKeyNameExpected ) ) { assertSame( ownerCollection.getOwner().getTable(), fk.getReferencedTable() ); hasOwnerFK = true; } } assertTrue( hasOwnerFK ); }
protected void checkDefaultJoinTableAndAllColumnNames( Metadata metadata, Class<?> ownerEntityClass, String ownerCollectionPropertyName, String expectedCollectionTableName, String ownerForeignKeyNameExpected, String[] columnNames) { final org.hibernate.mapping.Collection collection = metadata.getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); final org.hibernate.mapping.Table table = collection.getCollectionTable(); assertEquals( expectedCollectionTableName, table.getName() ); // The default owner and inverse join columns can only be computed if they have PK with 1 column. assertEquals( 1, collection.getOwner().getKey().getColumnSpan() ); assertEquals( ownerForeignKeyNameExpected, collection.getKey().getColumnIterator().next().getText() ); int columnNumber = table.getColumnSpan(); for ( int i = 0; i < columnNumber; i++ ) { assertEquals( columnNames[i], table.getColumn( i + 1 ).getName()); } }
); org.hibernate.mapping.OneToMany oneToMany = new org.hibernate.mapping.OneToMany( buildingContext, collection.getOwner() ); collection.setElement( oneToMany ); oneToMany.setReferencedEntityName( collectionType.getName() ); prop.setSelectable( false ); prop.setCollectionRole( collection.getRole() ); prop.setEntityName( collection.getOwner().getEntityName() ); prop.setValue( collection.getKey() ); referenced.addProperty( prop );
collection.setFetchMode( FetchMode.SELECT ); collection.setSubselectLoadable( true ); collection.getOwner().setSubselectLoadableCollections( true );
binding.setSubselectLoadable( true ); binding.getOwner().setSubselectLoadableCollections( true ); break;
final OneToMany elementBinding = new OneToMany( getMappingDocument(), getCollectionBinding().getOwner() ); collectionBinding.setElement( elementBinding );