use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class SchemaToolTransactionHandlingTest method testValidateInExistingJtaTransaction.
@Test
public void testValidateInExistingJtaTransaction() {
// start a JTA transaction...
try {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
} catch (Exception e) {
throw new RuntimeException("Unable to being JTA transaction prior to starting test", e);
}
// hold reference to Transaction object
final Transaction jtaTransaction;
try {
jtaTransaction = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().getTransaction();
} catch (SystemException e) {
throw new RuntimeException("Unable to access JTA Transaction prior to starting test", e);
}
final StandardServiceRegistry registry = buildJtaStandardServiceRegistry();
// perform the test...
try {
final SchemaManagementTool smt = registry.getService(SchemaManagementTool.class);
final Metadata mappings = buildMappings(registry);
// first make the schema exist...
try {
smt.getSchemaCreator(Collections.emptyMap()).doCreation(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
} catch (Exception e) {
throw new RuntimeException("Unable to create schema to validation tests", e);
}
try {
smt.getSchemaValidator(Collections.emptyMap()).doValidation(mappings, ExecutionOptionsTestImpl.INSTANCE);
} finally {
try {
smt.getSchemaDropper(Collections.emptyMap()).doDrop(mappings, ExecutionOptionsTestImpl.INSTANCE, SourceDescriptorImpl.INSTANCE, TargetDescriptorImpl.INSTANCE);
} catch (Exception ignore) {
// ignore
}
}
} finally {
try {
jtaTransaction.commit();
((StandardServiceRegistryImpl) registry).destroy();
} catch (Exception e) {
// not much we can do...
}
}
}
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 ExtendsTest method testUnionSubclass.
@Test
public void testUnionSubclass() {
Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/unionsubclass.hbm.xml").buildMetadata();
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Person"));
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Customer"));
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class ExtendsTest method testNwaitingForSuper.
@Test
public void testNwaitingForSuper() {
Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/Customer.hbm.xml").addResource(getBaseForMappings() + "extendshbm/Employee.hbm.xml").addResource(getBaseForMappings() + "extendshbm/Person.hbm.xml").buildMetadata();
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Customer"));
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Person"));
assertNotNull(metadata.getEntityBinding("org.hibernate.test.extendshbm.Employee"));
}
use of org.hibernate.boot.Metadata in project hibernate-orm by hibernate.
the class ExtendsTest method testJoinedSubclassAndEntityNamesOnly.
@Test
public void testJoinedSubclassAndEntityNamesOnly() {
Metadata metadata = new MetadataSources(serviceRegistry).addResource(getBaseForMappings() + "extendshbm/entitynames.hbm.xml").buildMetadata();
assertNotNull(metadata.getEntityBinding("EntityHasName"));
assertNotNull(metadata.getEntityBinding("EntityCompany"));
}
Aggregations