use of org.hibernate.boot.internal.MetadataImpl in project hibernate-orm by hibernate.
the class BasicModelingTest method testMetamodelBuilding.
@Test
@TestForIssue(jiraKey = "HHH-9042")
public void testMetamodelBuilding() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Person.class).getMetadataBuilder().applyAttributeConverter(SexConverter.class).build();
((MetadataImpl) metadata).validate();
PersistentClass personBinding = metadata.getEntityBinding(Person.class.getName());
assertNotNull(personBinding);
PersistentClass personAuditBinding = metadata.getEntityBinding(Person.class.getName() + "_AUD");
assertNotNull(personAuditBinding);
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.internal.MetadataImpl in project hibernate-orm by hibernate.
the class GeneratedValueTest method testGeneratedUuidId.
@Test
public void testGeneratedUuidId() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TheEntity.class).buildMetadata();
((MetadataImpl) metadata).validate();
PersistentClass entityBinding = metadata.getEntityBinding(TheEntity.class.getName());
assertEquals(UUID.class, entityBinding.getIdentifier().getType().getReturnedClass());
IdentifierGenerator generator = entityBinding.getIdentifier().createIdentifierGenerator(metadata.getIdentifierGeneratorFactory(), metadata.getDatabase().getDialect(), null, null, (RootClass) entityBinding);
assertTyping(UUIDGenerator.class, generator);
// now a functional test
SessionFactory sf = metadata.buildSessionFactory();
try {
TheEntity theEntity = new TheEntity();
Session s = sf.openSession();
s.beginTransaction();
s.save(theEntity);
s.getTransaction().commit();
s.close();
assertNotNull(theEntity.id);
s = sf.openSession();
s.beginTransaction();
try {
s.delete(theEntity);
s.getTransaction().commit();
} catch (Exception e) {
s.getTransaction().rollback();
throw e;
} finally {
s.close();
}
} finally {
try {
sf.close();
} catch (Exception ignore) {
}
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.internal.MetadataImpl in project hibernate-orm by hibernate.
the class AndNationalizedTests method basicTest.
@Test
@TestForIssue(jiraKey = "HHH-9599")
public void basicTest() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(TestEntity.class).buildMetadata();
((MetadataImpl) metadata).validate();
final PersistentClass entityBinding = metadata.getEntityBinding(TestEntity.class.getName());
if (metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect) {
// See issue HHH-10693
assertEquals(Types.VARCHAR, entityBinding.getProperty("name").getType().sqlTypes(metadata)[0]);
} else {
assertEquals(Types.NVARCHAR, entityBinding.getProperty("name").getType().sqlTypes(metadata)[0]);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations