use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.
the class EmbeddableIntegratorTest method testWithoutIntegrator.
/**
* Throws a mapping exception because DollarValue is not mapped
*/
@Test
public void testWithoutIntegrator() {
SessionFactory sf = new Configuration().addAnnotatedClass(Investor.class).setProperty("hibernate.hbm2ddl.auto", "create-drop").buildSessionFactory();
try {
Session sess = sf.openSession();
try {
sess.getTransaction().begin();
Investor myInv = getInvestor();
myInv.setId(1L);
sess.save(myInv);
sess.flush();
fail("A JDBCException expected");
sess.clear();
Investor inv = (Investor) sess.get(Investor.class, 1L);
assertEquals(new BigDecimal("100"), inv.getInvestments().get(0).getAmount().getAmount());
} catch (PersistenceException e) {
assertTyping(JDBCException.class, e.getCause());
sess.getTransaction().rollback();
}
sess.close();
} finally {
sf.close();
}
}
use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.
the class BasicHibernateAnnotationsTest method testTypeDefWithoutNameAndDefaultForTypeAttributes.
@Test
public void testTypeDefWithoutNameAndDefaultForTypeAttributes() {
SessionFactory sf = null;
StandardServiceRegistryImpl ssr = null;
try {
Configuration config = new Configuration();
config.addAnnotatedClass(LocalContactDetails.class);
ssr = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
sf = config.buildSessionFactory(ssr);
fail("Did not throw expected exception");
} catch (AnnotationException ex) {
assertEquals("Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType", ex.getMessage());
} finally {
if (ssr != null) {
ssr.destroy();
}
if (sf != null) {
sf.close();
}
}
}
use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.
the class AbstractBulkCompositeIdTest method constructConfiguration.
@Override
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
configuration.setProperty(AvailableSettings.HQL_BULK_ID_STRATEGY, getMultiTableBulkIdStrategyClass().getName());
return configuration;
}
use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.
the class LazyInCacheTestTask method prepare.
public void prepare() {
Configuration cfg = new Configuration();
cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
prepare(cfg);
}
use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.
the class SimpleLazyGroupUpdateTestTask method prepare.
@Override
public void prepare() {
Configuration cfg = new Configuration();
cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
super.prepare(cfg);
Session s = getFactory().openSession();
s.beginTransaction();
s.save(new TestEntity(1, "entity 1", "blah", REALLY_BIG_STRING));
s.getTransaction().commit();
s.close();
}
Aggregations