Search in sources :

Example 96 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class LazyLoadingIntegrationTestTask 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, "false");
    super.prepare(cfg);
    Session s = getFactory().openSession();
    s.beginTransaction();
    Parent parent = new Parent();
    parent.setChildren(new ArrayList<Child>(CHILDREN_SIZE));
    for (int i = 0; i < CHILDREN_SIZE; i++) {
        final Child child = new Child();
        // Association management should kick in here
        child.setParent(parent);
        s.persist(child);
        lastChildID = child.getId();
    }
    s.persist(parent);
    parentID = parent.getId();
    s.getTransaction().commit();
    s.clear();
    s.close();
}
Also used : Configuration(org.hibernate.cfg.Configuration) Session(org.hibernate.Session)

Example 97 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class SQLServerDialectTest method constructConfiguration.

@Override
protected Configuration constructConfiguration() {
    Configuration configuration = super.constructConfiguration();
    configuration.setProperty(AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString());
    return configuration;
}
Also used : Configuration(org.hibernate.cfg.Configuration)

Example 98 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class CriterionTest method testIlikeRendering.

@Test
public void testIlikeRendering() {
    SessionFactory sf = new Configuration().addAnnotatedClass(IrrelevantEntity.class).setProperty(AvailableSettings.DIALECT, IlikeSupportingDialect.class.getName()).setProperty(Environment.HBM2DDL_AUTO, "create-drop").buildSessionFactory();
    try {
        final Criteria criteria = sf.openSession().createCriteria(IrrelevantEntity.class);
        final CriteriaQueryTranslator translator = new CriteriaQueryTranslator((SessionFactoryImplementor) sf, (CriteriaImpl) criteria, IrrelevantEntity.class.getName(), "a");
        final Criterion ilikeExpression = Restrictions.ilike("name", "abc");
        final String ilikeExpressionSqlFragment = ilikeExpression.toSqlString(criteria, translator);
        assertEquals("a.name insensitiveLike ?", ilikeExpressionSqlFragment);
    } finally {
        sf.close();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Criterion(org.hibernate.criterion.Criterion) IrrelevantEntity(org.hibernate.IrrelevantEntity) Criteria(org.hibernate.Criteria) CriteriaQueryTranslator(org.hibernate.loader.criteria.CriteriaQueryTranslator) Test(org.junit.Test)

Example 99 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class CriterionTest method testIlikeMimicing.

@Test
public void testIlikeMimicing() {
    SessionFactory sf = new Configuration().addAnnotatedClass(IrrelevantEntity.class).setProperty(AvailableSettings.DIALECT, NonIlikeSupportingDialect.class.getName()).setProperty(Environment.HBM2DDL_AUTO, "create-drop").buildSessionFactory();
    try {
        final Criteria criteria = sf.openSession().createCriteria(IrrelevantEntity.class);
        final CriteriaQueryTranslator translator = new CriteriaQueryTranslator((SessionFactoryImplementor) sf, (CriteriaImpl) criteria, IrrelevantEntity.class.getName(), "a");
        final Criterion ilikeExpression = Restrictions.ilike("name", "abc");
        final String ilikeExpressionSqlFragment = ilikeExpression.toSqlString(criteria, translator);
        assertEquals("lowLowLow(a.name) like ?", ilikeExpressionSqlFragment);
    } finally {
        sf.close();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Criterion(org.hibernate.criterion.Criterion) IrrelevantEntity(org.hibernate.IrrelevantEntity) Criteria(org.hibernate.Criteria) CriteriaQueryTranslator(org.hibernate.loader.criteria.CriteriaQueryTranslator) Test(org.junit.Test)

Example 100 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class UserTypeMappingTest method setup.

@Before
public void setup() {
    cfg = new Configuration();
    Properties p = new Properties();
    p.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect");
    p.put("hibernate.connection.driver_class", "org.h2.Driver");
    p.put("hibernate.connection.url", "jdbc:h2:mem:");
    p.put("hibernate.connection.username", "sa");
    p.put("hibernate.connection.password", "");
    cfg.setProperties(p);
    serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(cfg.getProperties());
}
Also used : Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

Configuration (org.hibernate.cfg.Configuration)179 Test (org.junit.Test)66 Session (org.hibernate.Session)37 SessionFactory (org.hibernate.SessionFactory)34 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)27 BeforeClass (org.junit.BeforeClass)19 Before (org.junit.Before)18 ServiceRegistry (org.hibernate.service.ServiceRegistry)14 File (java.io.File)13 Properties (java.util.Properties)11 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)9 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 HibernateException (org.hibernate.HibernateException)7 MappingException (org.hibernate.MappingException)7 Transaction (org.hibernate.Transaction)7 URL (java.net.URL)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 TestForIssue (org.hibernate.testing.TestForIssue)6 EntityTuplizer (org.hibernate.tuple.entity.EntityTuplizer)6 BigDecimal (java.math.BigDecimal)5