use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class DiscriminatorOptionsTest method testPropertyBasedDiscriminatorForcing.
@Test
public void testPropertyBasedDiscriminatorForcing() throws Exception {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(BaseClass2.class).addAnnotatedClass(SubClass2.class).getMetadataBuilder().enableImplicitForcingOfDiscriminatorsInSelect(true).build();
PersistentClass persistentClass = metadata.getEntityBinding(BaseClass2.class.getName());
assertNotNull(persistentClass);
assertTrue(persistentClass instanceof RootClass);
RootClass root = (RootClass) persistentClass;
assertTrue("Discriminator should be forced by property", root.isForceDiscriminator());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class ManyToManyImplicitNamingTest method checkDefaultJoinTablAndJoinColumnNames.
protected void checkDefaultJoinTablAndJoinColumnNames(Class<?> ownerEntityClass, String ownerCollectionPropertyName, String inverseCollectionPropertyName, String expectedCollectionTableName, 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);
// The default owner and inverse join columns can only be computed if they have PK with 1 column.
assertEquals(1, ownerCollection.getOwner().getKey().getColumnSpan());
assertEquals(ownerForeignKeyNameExpected, ownerCollection.getKey().getColumnIterator().next().getText());
final EntityType associatedEntityType = (EntityType) ownerCollection.getElement().getType();
final PersistentClass associatedPersistentClass = metadata().getEntityBinding(associatedEntityType.getAssociatedEntityName());
assertEquals(1, associatedPersistentClass.getKey().getColumnSpan());
if (inverseCollectionPropertyName != null) {
final org.hibernate.mapping.Collection inverseCollection = metadata().getCollectionBinding(associatedPersistentClass.getEntityName() + '.' + inverseCollectionPropertyName);
assertEquals(inverseForeignKeyNameExpected, inverseCollection.getKey().getColumnIterator().next().getText());
}
boolean hasOwnerFK = false;
boolean hasInverseFK = 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;
} else if (fk.getColumn(0).getText().equals(inverseForeignKeyNameExpected)) {
assertSame(associatedPersistentClass.getTable(), fk.getReferencedTable());
hasInverseFK = true;
}
}
assertTrue(hasOwnerFK);
assertTrue(hasInverseFK);
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class AbstractJPAIndexTest method testSecondaryTableIndex.
@Test
public void testSecondaryTableIndex() {
PersistentClass entity = metadata().getEntityBinding(Car.class.getName());
Join join = (Join) entity.getJoinIterator().next();
Iterator<Index> itr = join.getTable().getIndexIterator();
assertTrue(itr.hasNext());
Index index = itr.next();
assertFalse(itr.hasNext());
assertTrue("index name is not generated", StringHelper.isNotEmpty(index.getName()));
assertEquals(2, index.getColumnSpan());
Iterator<Column> columnIterator = index.getColumnIterator();
Column column = columnIterator.next();
assertEquals("dealer_name", column.getName());
column = columnIterator.next();
assertEquals("rate", column.getName());
assertSame(join.getTable(), index.getTable());
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class PersisterTest method testEntityEntityPersisterAndPersisterSpecified.
@Test
public void testEntityEntityPersisterAndPersisterSpecified() throws Exception {
//checks to see that the persister specified with the @Persister annotation takes precedence if a @Entity.persister() is also specified
PersistentClass persistentClass = metadata().getEntityBinding(Deck.class.getName());
assertEquals("Incorrect Persister class for " + persistentClass.getMappedClass(), EntityPersister.class, persistentClass.getEntityPersisterClass());
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class PersisterTest method testEntityEntityPersisterSpecified.
@Test
public void testEntityEntityPersisterSpecified() throws Exception {
//tests the persister specified with an @Entity.persister()
PersistentClass persistentClass = metadata().getEntityBinding(Card.class.getName());
assertEquals("Incorrect Persister class for " + persistentClass.getMappedClass(), SingleTableEntityPersister.class, persistentClass.getEntityPersisterClass());
}
Aggregations