use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class JoinColumnOverrideTest method testBlownPrecision.
@Test
@TestForIssue(jiraKey = "ANN-748")
public void testBlownPrecision() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, "SQLServer").build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Bunny.class).addAnnotatedClass(PointyTooth.class).addAnnotatedClass(TwinkleToes.class).buildMetadata();
boolean foundPointyToothCreate = false;
boolean foundTwinkleToesCreate = false;
List<String> commands = new SchemaCreatorImpl(ssr).generateCreationCommands(metadata, false);
for (String command : commands) {
log.debug(command);
if (expectedSqlPointyTooth.equals(command)) {
foundPointyToothCreate = true;
} else if (expectedSqlTwinkleToes.equals(command)) {
foundTwinkleToesCreate = true;
}
}
assertTrue("Expected create table command for PointyTooth entity not found", foundPointyToothCreate);
assertTrue("Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.Metadata 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.boot.Metadata in project hibernate-orm by hibernate.
the class DuplicatedDiscriminatorValueTest method tryBuildingSessionFactory.
private void tryBuildingSessionFactory(Class... annotatedClasses) {
final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build();
try {
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (Class annotatedClass : annotatedClasses) {
metadataSources.addAnnotatedClass(annotatedClass);
}
final Metadata metadata = metadataSources.buildMetadata();
final SessionFactory sessionFactory = metadata.buildSessionFactory();
sessionFactory.close();
} finally {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class LongKeyNamingStrategyTest method testWithCustomNamingStrategy.
@Test
public void testWithCustomNamingStrategy() throws Exception {
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(Address.class).addAnnotatedClass(Person.class).getMetadataBuilder().applyImplicitNamingStrategy(new LongIdentifierNamingStrategy()).build();
org.hibernate.mapping.ForeignKey foreignKey = (org.hibernate.mapping.ForeignKey) metadata.getEntityBinding(Address.class.getName()).getTable().getForeignKeyIterator().next();
assertEquals("FK_way_longer_than_the_30_char", foreignKey.getName());
UniqueKey uniqueKey = metadata.getEntityBinding(Address.class.getName()).getTable().getUniqueKeyIterator().next();
assertEquals("UK_way_longer_than_the_30_char", uniqueKey.getName());
org.hibernate.mapping.Index index = metadata.getEntityBinding(Address.class.getName()).getTable().getIndexIterator().next();
assertEquals("IDX_way_longer_than_the_30_cha", index.getName());
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class NamingStrategyTest method testWithJpaCompliantNamingStrategy.
@Test
public void testWithJpaCompliantNamingStrategy() throws Exception {
Metadata metadata = new MetadataSources(serviceRegistry).addAnnotatedClass(A.class).addAnnotatedClass(AddressEntry.class).getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
Collection collectionBinding = metadata.getCollectionBinding(A.class.getName() + ".address");
assertEquals("Expecting A#address collection table name (implicit) to be [A_address] per JPA spec (section 11.1.8)", "A_ADDRESS", collectionBinding.getCollectionTable().getQuotedName().toUpperCase(Locale.ROOT));
}
Aggregations