@Override public org.hibernate.mapping.Collection getCollectionBinding(String role) { return delegate.getCollectionBinding( role ); }
MetadataImplementor metadata = (MetadataImplementor) factory; if ( type instanceof CollectionType && existingType instanceof CollectionType ) { Collection thisCollection = metadata.getCollectionBinding( ( (CollectionType) existingType ).getRole() ); Collection otherCollection = metadata.getCollectionBinding( ( (CollectionType) type ).getRole() );
private boolean isDefaultColumnPresent(String collectionOwner, String propertyName, String suffix) { final Collection collection = metadata().getCollectionBinding( collectionOwner + "." + propertyName ); final Iterator columnIterator = collection.getCollectionTable().getColumnIterator(); boolean hasDefault = false; while ( columnIterator.hasNext() ) { Column column = (Column) columnIterator.next(); if ( (propertyName + suffix).equals( column.getName() ) ) hasDefault = true; } return hasDefault; }
private void isCollectionColumnPresent(String collectionOwner, String propertyName, String columnName) { final Collection collection = metadata().getCollectionBinding( collectionOwner + "." + propertyName ); final Iterator columnIterator = collection.getCollectionTable().getColumnIterator(); boolean hasDefault = false; while ( columnIterator.hasNext() ) { Column column = (Column) columnIterator.next(); if ( columnName.equals( column.getName() ) ) hasDefault = true; } assertTrue( "Could not find " + columnName, hasDefault ); }
protected void checkDefaultCollectionTableName( Class<?> ownerEntityClass, String ownerCollectionPropertyName, String expectedCollectionTableName) { final org.hibernate.mapping.Collection collection = metadata().getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); final org.hibernate.mapping.Table table = collection.getCollectionTable(); assertEquals( expectedCollectionTableName, table.getName() ); }
@Test @TestForIssue(jiraKey = "HHH-9327") public void testManyToManyCollectionTable() { final Collection collectionMapping = metadata.getCollectionBinding( Category.class.getName() + "." + "items" ); final String expectedTableName = transformEntityName( Category.class.getName() ) + "_" + transformEntityName( Item.class.getName() ); assertEquals( expectedTableName, collectionMapping.getCollectionTable().getName() ); }
@Test @TestForIssue(jiraKey = "HHH-9327") public void testElementCollectionTable() { final Collection collectionMapping = metadata.getCollectionBinding( Workflow.class.getName() + ".localized" ); final String expectedTableName = transformEntityName( Workflow.class.getName() ) + "_localized"; assertEquals( expectedTableName, collectionMapping.getCollectionTable().getName() ); }
@Test public void testCollectionPersisterSpecified() throws Exception { //tests the persister specified by the @Persister annotation on a collection Collection collection = metadata().getCollectionBinding( Deck.class.getName() + ".cards" ); assertEquals( "Incorrect Persister class for collection " + collection.getRole(), CollectionPersister.class, collection.getCollectionPersisterClass() ); }
@Test @TestForIssue( jiraKey = "HHH-9327") public void testManyToManyForeignKeys() { final Collection ownerCollectionMapping = metadata.getCollectionBinding( Category.class.getName() + "." + "items" ); final String expectedOwnerFK = transformEntityName( Category.class.getName() ) + "_id"; final String expectedInverseFK = transformEntityName( Item.class.getName() ) + "_items_id"; boolean ownerFKFound = false; boolean inverseFKFound = false; for ( Iterator it = ownerCollectionMapping.getCollectionTable().getForeignKeyIterator(); it.hasNext(); ) { final String fkColumnName = ( (ForeignKey) it.next() ).getColumn( 0 ).getName(); if ( expectedOwnerFK.equals( fkColumnName ) ) { ownerFKFound = true; } else if ( expectedInverseFK.equals( fkColumnName ) ) { inverseFKFound = true; } } assertTrue( ownerFKFound ); assertTrue( inverseFKFound ); }
@Test public void testQuoteManytoMany() { Session s = openSession(); Transaction tx = s.beginTransaction(); User u = new User(); s.persist( u ); Role r = new Role(); s.persist( r ); u.getRoles().add( r ); s.flush(); s.clear(); u = (User) s.get( User.class, u.getId() ); assertEquals( 1, u.getRoles().size() ); tx.rollback(); String role = User.class.getName() + ".roles"; assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() ); s.close(); }
@Test public void testQuoteManytoMany() { String role = User.class.getName() + ".roles"; assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() ); Session s = openSession(); s.beginTransaction(); User u = new User(); s.persist( u ); Role r = new Role(); s.persist( r ); u.getRoles().add( r ); s.flush(); s.clear(); u = s.get( User.class, u.getId() ); assertEquals( 1, u.getRoles().size() ); s.getTransaction().rollback(); s.close(); }
assertEquals( "BoyFavoriteNumbers", metadata().getCollectionBinding( Boy.class.getName() + '.' + "favoriteNumbers" ) .getCollectionTable().getName() );
assertEquals( "BoyFavoriteNumbers", metadata().getCollectionBinding( Boy.class.getName() + '.' + "favoriteNumbers" ) .getCollectionTable().getName() );
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 ); }
String ownerForeignKeyNameExpected, String inverseForeignKeyNameExpected) { final org.hibernate.mapping.Collection collection = metadata().getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); final org.hibernate.mapping.Table table = collection.getCollectionTable(); assertEquals( expectedCollectionTableName, table.getName() ); final org.hibernate.mapping.Collection ownerCollection = metadata().getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); assertEquals( 1, associatedPersistentClass.getKey().getColumnSpan() ); if ( inverseCollectionPropertyName != null ) { final org.hibernate.mapping.Collection inverseCollection = metadata().getCollectionBinding( associatedPersistentClass.getEntityName() + '.' + inverseCollectionPropertyName );
@Override public org.hibernate.mapping.Collection getCollectionBinding(String role) { return delegate.getCollectionBinding( role ); }