use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class ForeignKeyMigrationTest method testMigrationOfForeignKeys.
@Test
@TestForIssue(jiraKey = "HHH-9716")
public // @FailureExpected( jiraKey = "HHH-9716" )
void testMigrationOfForeignKeys() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Box.class).addAnnotatedClass(Thing.class).buildMetadata();
metadata.validate();
// first create the schema...
new SchemaExport().create(EnumSet.of(TargetType.DATABASE), metadata);
try {
// try to update the just created schema
new SchemaUpdate().execute(EnumSet.of(TargetType.DATABASE), metadata);
} finally {
// clean up
new SchemaExport().drop(EnumSet.of(TargetType.DATABASE), metadata);
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class ClosedFactoryTests method testClosedChecks.
@Test
public void testClosedChecks() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.JPA_CLOSED_COMPLIANCE, "true").build();
try {
final SessionFactoryBuilderImplementor factoryBuilder = (SessionFactoryBuilderImplementor) new MetadataSources(ssr).buildMetadata().getSessionFactoryBuilder();
final SessionFactory sf = factoryBuilder.build();
sf.close();
assertTrue(sf.isClosed());
try {
sf.getCache();
fail("#getCache did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#getCache failed, but not with the expected IllegalStateException : " + e.toString());
}
try {
sf.getMetamodel();
fail("#getMetamodel did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#getMetamodel failed, but not with the expected IllegalStateException : " + e.toString());
}
try {
sf.getCriteriaBuilder();
fail("#getCriteriaBuilder did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#getCriteriaBuilder failed, but not with the expected IllegalStateException : " + e.toString());
}
try {
sf.getProperties();
fail("#getProperties did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#getProperties failed, but not with the expected IllegalStateException : " + e.toString());
}
try {
sf.getPersistenceUnitUtil();
fail("#getPersistenceUnitUtil did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#getPersistenceUnitUtil failed, but not with the expected IllegalStateException : " + e.toString());
}
try {
sf.close();
fail("#close did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#close failed, but not with the expected IllegalStateException : " + e.toString());
}
try {
sf.createEntityManager();
fail("#createEntityManager did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#createEntityManager failed, but not with the expected IllegalStateException : " + e.toString());
}
try {
sf.createEntityManager(Collections.emptyMap());
fail("#createEntityManager(Map) did not fail");
} catch (IllegalStateException expected) {
// this is the expected outcome
} catch (Exception e) {
fail("#createEntityManager(Map) failed, but not with the expected IllegalStateException : " + e.toString());
}
} catch (Exception e) {
// if an exception is
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class EntityTransactionTests method testSetRollbackOnlyOutcomeExpectations.
@Test
public void testSetRollbackOnlyOutcomeExpectations() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.JPA_TRANSACTION_COMPLIANCE, "true").build();
try {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).buildMetadata().buildSessionFactory();
try {
inSession(sessionFactory, session -> {
final Transaction transaction = session.getTransaction();
transaction.begin();
try {
assertTrue(transaction.isActive());
transaction.setRollbackOnly();
assertTrue(transaction.isActive());
assertTrue(transaction.getRollbackOnly());
} finally {
if (transaction.isActive()) {
transaction.rollback();
}
}
});
inSession(sessionFactory, session -> {
final Transaction transaction = session.getTransaction();
transaction.begin();
try {
assertTrue(transaction.isActive());
transaction.setRollbackOnly();
assertTrue(transaction.isActive());
assertTrue(transaction.getRollbackOnly());
// now try to commit, this should force a rollback
try {
transaction.commit();
} catch (RollbackException e) {
assertFalse(transaction.isActive());
assertThat(transaction.getStatus(), CoreMatchers.is(TransactionStatus.ROLLED_BACK));
}
} finally {
if (transaction.isActive()) {
transaction.rollback();
}
}
});
} finally {
sessionFactory.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class EntityTransactionTests method testGetRollbackOnlyExpectations.
@Test
public void testGetRollbackOnlyExpectations() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.JPA_TRANSACTION_COMPLIANCE, "true").build();
try {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).buildMetadata().buildSessionFactory();
try {
inSession(sessionFactory, session -> {
final Transaction transaction = session.getTransaction();
assertFalse(transaction.isActive());
try {
transaction.getRollbackOnly();
fail("Expecting failure #getRollbackOnly on non-active txn");
} catch (IllegalStateException expected) {
}
});
} finally {
sessionFactory.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.boot.registry.StandardServiceRegistry in project hibernate-orm by hibernate.
the class EntityTransactionTests method testSetRollbackOnlyExpectations.
@Test
public void testSetRollbackOnlyExpectations() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.JPA_TRANSACTION_COMPLIANCE, "true").build();
try {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources(ssr).buildMetadata().buildSessionFactory();
try {
inSession(sessionFactory, session -> {
final Transaction transaction = session.getTransaction();
assertFalse(transaction.isActive());
try {
transaction.setRollbackOnly();
fail("Expecting failure #setRollbackOnly on non-active txn");
} catch (IllegalStateException expected) {
}
});
} finally {
sessionFactory.close();
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
Aggregations