Search in sources :

Example 21 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class CoalesceTest method HHH_10463_NullInCoalesce_PostgreSQL_Workaround.

@Test
@RequiresDialect(PostgreSQL81Dialect.class)
public void HHH_10463_NullInCoalesce_PostgreSQL_Workaround() {
    doInHibernate(this::sessionFactory, session -> {
        Query query = session.createQuery("from Person p where p.name = coalesce(cast( :name as string) , p.name) ");
        query.setParameter("name", null);
        List<Person> resultList = query.getResultList();
        assertThat(resultList, hasItem(person));
    });
}
Also used : Query(org.hibernate.query.Query) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 22 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class UUIDBasedIdInterpretationTest method testBinaryRuntimeUsage.

@Test
@TestForIssue(jiraKey = "HHH-10564")
@RequiresDialect(H2Dialect.class)
public void testBinaryRuntimeUsage() {
    StandardServiceRegistry ssr = buildStandardServiceRegistry(H2Dialect.class, true);
    try {
        final Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(UuidIdEntity.class).buildMetadata();
        final SessionFactory sf = metadata.buildSessionFactory();
        try {
            Session s = sf.openSession();
            try {
                s.beginTransaction();
                s.byId(UuidIdEntity.class).load(UUID.randomUUID());
                s.getTransaction().commit();
            } finally {
                s.close();
            }
        } finally {
            sf.close();
        }
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 23 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class SQLServer2012SequenceGeneratorTest method testStartOfSequence.

/**
     * SQL server requires that sequence be initialized to something other than the minimum value for the type
	 * (e.g., Long.MIN_VALUE). For generator = "sequence", the initial value must be provided as a parameter.
	 * For this test, the sequence is initialized to 10.
	 */
@Test
@TestForIssue(jiraKey = "HHH-8814")
@RequiresDialect(value = SQLServer2012Dialect.class)
public void testStartOfSequence() throws Exception {
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    final Person person = new Person();
    s.persist(person);
    tx.commit();
    s.close();
    assertTrue(person.getId() == 10);
    s = openSession();
    tx = s.beginTransaction();
    s.createQuery("delete from Person").executeUpdate();
    tx.commit();
    s.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 24 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class FooBarTest method testUserProvidedConnection.

@Test
@RequiresDialect(value = H2Dialect.class, comment = "this is more like a unit test")
public void testUserProvidedConnection() throws Exception {
    ConnectionProvider dcp = ConnectionProviderBuilder.buildConnectionProvider();
    Session s = sessionFactory().withOptions().connection(dcp.getConnection()).openSession();
    Transaction tx = s.beginTransaction();
    s.createQuery("from Fo").list();
    tx.commit();
    Connection c = s.disconnect();
    assertTrue(c != null);
    s.reconnect(c);
    tx = s.beginTransaction();
    s.createQuery("from Fo").list();
    tx.commit();
    c.close();
}
Also used : Transaction(org.hibernate.Transaction) Connection(java.sql.Connection) ConnectionProvider(org.hibernate.engine.jdbc.connections.spi.ConnectionProvider) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Example 25 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class PessimisticWriteLockTimeoutTest method testNoWait.

@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL81Dialect.class, SQLServer2005Dialect.class })
public void testNoWait() throws NoSuchFieldException, IllegalAccessException {
    Session session = sessionFactory().openSession();
    session.beginTransaction();
    try {
        session.createQuery("select a from A a", A.class).unwrap(org.hibernate.query.Query.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.NO_WAIT)).list();
        String lockingQuery = sqlStatementInterceptor.getSqlQueries().getLast();
        assertTrue(lockingQuery.toLowerCase().contains("nowait"));
    } finally {
        session.getTransaction().commit();
        session.close();
    }
}
Also used : LockOptions(org.hibernate.LockOptions) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Aggregations

RequiresDialect (org.hibernate.testing.RequiresDialect)36 Test (org.junit.Test)34 Session (org.hibernate.Session)18 TestForIssue (org.hibernate.testing.TestForIssue)13 EntityManager (javax.persistence.EntityManager)9 RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)7 Callable (java.util.concurrent.Callable)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 Transaction (org.hibernate.Transaction)6 HashMap (java.util.HashMap)5 Phone (org.hibernate.userguide.model.Phone)5 LockTimeoutException (javax.persistence.LockTimeoutException)4 List (java.util.List)3 LockOptions (org.hibernate.LockOptions)3 FailureExpected (org.hibernate.testing.FailureExpected)3 Call (org.hibernate.userguide.model.Call)3 Query (javax.persistence.Query)2 QueryTimeoutException (javax.persistence.QueryTimeoutException)2 MetadataSources (org.hibernate.boot.MetadataSources)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)2