Search in sources :

Example 61 with SkipForDialect

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

the class FumTest method testCompositeKeyPathExpressions.

@Test
@SkipForDialect(value = SybaseASE15Dialect.class, jiraKey = "HHH-3690")
public void testCompositeKeyPathExpressions() throws Exception {
    Session s = openSession();
    s.beginTransaction();
    s.createQuery("select fum1.fo from Fum fum1 where fum1.fo.fum is not null").list();
    s.createQuery("from Fum fum1 where fum1.fo.fum is not null order by fum1.fo.fum").list();
    if (!(getDialect() instanceof MySQLDialect) && !(getDialect() instanceof HSQLDialect) && !(getDialect() instanceof MckoiDialect) && !(getDialect() instanceof PointbaseDialect)) {
        s.createQuery("from Fum fum1 where exists elements(fum1.friends)").list();
        if (!(getDialect() instanceof TimesTenDialect)) {
            // can't execute because TimesTen can't do subqueries combined with aggreations
            s.createQuery("from Fum fum1 where size(fum1.friends) = 0").list();
        }
    }
    s.createQuery("select elements(fum1.friends) from Fum fum1").list();
    s.createQuery("from Fum fum1, fr in elements( fum1.friends )").list();
    s.getTransaction().commit();
    s.close();
}
Also used : HSQLDialect(org.hibernate.dialect.HSQLDialect) MckoiDialect(org.hibernate.dialect.MckoiDialect) MySQLDialect(org.hibernate.dialect.MySQLDialect) TimesTenDialect(org.hibernate.dialect.TimesTenDialect) PointbaseDialect(org.hibernate.dialect.PointbaseDialect) Session(org.hibernate.Session) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 62 with SkipForDialect

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

the class QueryTest method testNullPositionalParameterParameter.

@Test
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNullPositionalParameterParameter() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    try {
        Item item = new Item("Mouse", "Micro$oft mouse");
        em.persist(item);
        Query q = em.createQuery("from Item i where i.intVal=?");
        Parameter p = new Parameter() {

            @Override
            public String getName() {
                return null;
            }

            @Override
            public Integer getPosition() {
                return 0;
            }

            @Override
            public Class getParameterType() {
                return Integer.class;
            }
        };
        q.setParameter(p, null);
        Parameter pGotten = q.getParameter(p.getPosition());
        List results = q.getResultList();
        // null != null
        assertEquals(0, results.size());
        q = em.createQuery("from Item i where i.intVal is null and ? is null");
        q.setParameter(p, null);
        results = q.getResultList();
        assertEquals(1, results.size());
        q = em.createQuery("from Item i where i.intVal is null or i.intVal = ?");
        q.setParameter(p, null);
        results = q.getResultList();
        assertEquals(1, results.size());
    } finally {
        if (em.getTransaction() != null && em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }
}
Also used : Item(org.hibernate.jpa.test.Item) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) Parameter(javax.persistence.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 63 with SkipForDialect

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

the class QueryTest method testNativeQueryNullNamedParameter.

@Test
@SkipForDialect(value = Oracle8iDialect.class, jiraKey = "HHH-10161", comment = "Cannot convert untyped null (assumed to be BINARY type) to NUMBER")
@SkipForDialect(value = PostgreSQL9Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint")
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNativeQueryNullNamedParameter() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    try {
        Item item = new Item("Mouse", "Micro$oft mouse");
        em.persist(item);
        // native queries don't seem to flush by default ?!?
        em.flush();
        Query q = em.createNativeQuery("select * from Item i where i.intVal=:iVal");
        q.setParameter("iVal", null);
        List results = q.getResultList();
        // null != null
        assertEquals(0, results.size());
        q = em.createNativeQuery("select * from Item i where (i.intVal is null) and (:iVal is null)");
        q.setParameter("iVal", null);
        results = q.getResultList();
        assertEquals(1, results.size());
        q = em.createNativeQuery("select * from Item i where i.intVal is null or i.intVal = :iVal");
        q.setParameter("iVal", null);
        results = q.getResultList();
        assertEquals(1, results.size());
    } finally {
        if (em.getTransaction() != null && em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }
}
Also used : Item(org.hibernate.jpa.test.Item) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 64 with SkipForDialect

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

the class QueryTest method testNullPositionalParameterParameterIncompatible.

@Test
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNullPositionalParameterParameterIncompatible() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    try {
        Item item = new Item("Mouse", "Micro$oft mouse");
        em.persist(item);
        Query q = em.createQuery("from Item i where i.intVal=?");
        Parameter p = new Parameter() {

            @Override
            public String getName() {
                return null;
            }

            @Override
            public Integer getPosition() {
                return 0;
            }

            @Override
            public Class getParameterType() {
                return Long.class;
            }
        };
        q.setParameter(p, null);
        Parameter pGotten = q.getParameter(p.getPosition());
        List results = q.getResultList();
        // null != null
        assertEquals(0, results.size());
        q = em.createQuery("from Item i where i.intVal is null and ? is null");
        q.setParameter(p, null);
        results = q.getResultList();
        assertEquals(1, results.size());
        q = em.createQuery("from Item i where i.intVal is null or i.intVal = ?");
        q.setParameter(p, null);
        results = q.getResultList();
        assertEquals(1, results.size());
    } finally {
        if (em.getTransaction() != null && em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }
}
Also used : Item(org.hibernate.jpa.test.Item) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) Parameter(javax.persistence.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 65 with SkipForDialect

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

the class QueryTest method testNullPositionalParameter.

@Test
@SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase")
public void testNullPositionalParameter() throws Exception {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    try {
        Item item = new Item("Mouse", "Micro$oft mouse");
        em.persist(item);
        Query q = em.createQuery("from Item i where i.intVal=?");
        q.setParameter(0, null);
        List results = q.getResultList();
        // null != null
        assertEquals(0, results.size());
        q = em.createQuery("from Item i where i.intVal is null and ? is null");
        q.setParameter(0, null);
        results = q.getResultList();
        assertEquals(1, results.size());
        q = em.createQuery("from Item i where i.intVal is null or i.intVal = ?");
        q.setParameter(0, null);
        results = q.getResultList();
        assertEquals(1, results.size());
    } finally {
        if (em.getTransaction() != null && em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
        em.close();
    }
}
Also used : Item(org.hibernate.jpa.test.Item) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) ArrayList(java.util.ArrayList) List(java.util.List) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Aggregations

SkipForDialect (org.hibernate.testing.SkipForDialect)87 Test (org.junit.Test)86 Session (org.hibernate.Session)66 Transaction (org.hibernate.Transaction)36 List (java.util.List)26 ArrayList (java.util.ArrayList)20 TestForIssue (org.hibernate.testing.TestForIssue)16 EntityManager (javax.persistence.EntityManager)15 Query (javax.persistence.Query)11 Item (org.hibernate.jpa.test.Item)10 Query (org.hibernate.Query)7 Parameter (javax.persistence.Parameter)6 BigDecimal (java.math.BigDecimal)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 SQLQuery (org.hibernate.SQLQuery)4 ScrollableResults (org.hibernate.ScrollableResults)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Date (java.util.Date)3 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)3