use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class Tests method testJpaJoinColumnPhysicalNaming.
@Test
@TestForIssue(jiraKey = "HHH-9961")
public void testJpaJoinColumnPhysicalNaming() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySettings(Environment.getProperties()).build();
try {
final MetadataSources metadataSources = new MetadataSources(ssr);
metadataSources.addAnnotatedClass(Language.class);
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE);
metadataBuilder.applyPhysicalNamingStrategy(PhysicalNamingStrategyImpl.INSTANCE);
final Metadata metadata = metadataBuilder.build();
((MetadataImplementor) metadata).validate();
final PersistentClass languageBinding = metadata.getEntityBinding(Language.class.getName());
final Property property = languageBinding.getProperty("fallBack");
Iterator itr = property.getValue().getColumnIterator();
assertTrue(itr.hasNext());
final Column column = (Column) itr.next();
assertFalse(itr.hasNext());
assertEquals("C_FALLBACK_ID", column.getName().toUpperCase(Locale.ROOT));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SimpleNationalizedTest method simpleNationalizedTest.
@Test
public void simpleNationalizedTest() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataSources ms = new MetadataSources(ssr);
ms.addAnnotatedClass(NationalizedEntity.class);
final Metadata metadata = ms.buildMetadata();
PersistentClass pc = metadata.getEntityBinding(NationalizedEntity.class.getName());
assertNotNull(pc);
Property prop = pc.getProperty("nvarcharAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(StringType.INSTANCE, prop.getType());
} else {
assertSame(StringNVarcharType.INSTANCE, prop.getType());
}
prop = pc.getProperty("materializedNclobAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(MaterializedClobType.INSTANCE, prop.getType());
} else {
assertSame(MaterializedNClobType.INSTANCE, prop.getType());
}
prop = pc.getProperty("nclobAtt");
assertSame(NClobType.INSTANCE, prop.getType());
prop = pc.getProperty("nlongvarcharcharAtt");
assertSame(NTextType.INSTANCE, prop.getType());
prop = pc.getProperty("ncharArrAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(CharacterArrayType.INSTANCE, prop.getType());
} else {
assertSame(StringNVarcharType.INSTANCE, prop.getType());
}
prop = pc.getProperty("ncharacterAtt");
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertSame(CharacterType.INSTANCE, prop.getType());
} else {
assertSame(CharacterNCharType.INSTANCE, prop.getType());
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class OneToOneSchemaTest method testUniqueKeyNotGeneratedViaAnnotations.
@Test
public void testUniqueKeyNotGeneratedViaAnnotations() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Parent.class).addAnnotatedClass(Child.class).buildMetadata();
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable(Identifier.toIdentifier("CHILD"));
assertFalse("UniqueKey was generated when it should not", childTable.getUniqueKeyIterator().hasNext());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SchemaUpdateSchemaNameTest method cleanup.
@After
public void cleanup() {
// Drops the table after the sql alter test.
StandardServiceRegistry ssr = null;
try {
// build simple configuration
final Configuration cfg = buildConfiguration(SimpleFirst.class);
// Build Standard Service Registry
ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
SessionFactory sf = cfg.buildSessionFactory(ssr);
try {
Session session = sf.openSession();
try {
session.getTransaction().begin();
session.createNativeQuery("DROP TABLE Simple").executeUpdate();
session.getTransaction().commit();
} catch (Throwable t) {
if (session.getTransaction().isActive()) {
session.getTransaction().rollback();
}
throw t;
} finally {
session.close();
}
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistryBuilder in project hibernate-orm by hibernate.
the class SchemaUpdateSchemaNameTest method testSqlAlterWithTableSchemaName.
@Test
public void testSqlAlterWithTableSchemaName() throws Exception {
StandardServiceRegistry ssr = null;
try {
final Configuration cfg = buildConfiguration(SimpleNext.class);
ssr = new StandardServiceRegistryBuilder(new BootstrapServiceRegistryBuilder().build(), cfg.getStandardServiceRegistryBuilder().getAggregatedCfgXml()).applySettings(cfg.getProperties()).build();
SessionFactory sf = cfg.buildSessionFactory(ssr);
try {
Session session = sf.openSession();
try {
session.getTransaction().begin();
session.createQuery("FROM Simple", SimpleNext.class).getResultList();
session.getTransaction().commit();
} catch (Throwable t) {
if (session.getTransaction().isActive()) {
session.getTransaction().rollback();
}
throw t;
} finally {
session.close();
}
} finally {
sf.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations