use of org.hibernate.boot.MetadataSources 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.MetadataSources in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingJpaCompliantStrategy.
@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingJpaCompliantStrategy() {
// Even in 4.3, with JPA compliant naming, Hibernate creates an unusable table...
final MetadataSources metadataSources = new MetadataSources();
try {
metadataSources.addAnnotatedClass(Input.class);
metadataSources.addAnnotatedClass(Ptx.class);
final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE).build();
assertSameTableUsed(metadata);
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingLegacyJpaStrategy.
@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingLegacyJpaStrategy() {
final MetadataSources metadataSources = new MetadataSources();
try {
metadataSources.addAnnotatedClass(Input.class);
metadataSources.addAnnotatedClass(Ptx.class);
final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE).build();
assertSameTableUsed(metadata);
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class BaseNamingTests method doTest.
@Test
public void doTest() {
final MetadataSources metadataSources = new MetadataSources();
try {
applySources(metadataSources);
final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(getImplicitNamingStrategyToUse()).build();
validateCustomer(metadata);
validateOrder(metadata);
validateZipCode(metadata);
validateCustomerRegisteredTrademarks(metadata);
validateCustomerAddresses(metadata);
validateCustomerOrders(metadata);
validateCustomerIndustries(metadata);
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.boot.MetadataSources in project hibernate-orm by hibernate.
the class SpreadNaturalIdTest method testSpreadNaturalIdDeclarationGivesMappingException.
@Test
@SuppressWarnings("EmptyCatchBlock")
public void testSpreadNaturalIdDeclarationGivesMappingException() {
final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Principal.class).addAnnotatedClass(User.class);
try {
metadataSources.buildMetadata();
fail("Expected binders to throw an exception");
} catch (AnnotationException expected) {
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
Aggregations