Search in sources :

Example 1 with TransactionUtil2.inTransaction

use of org.hibernate.testing.transaction.TransactionUtil2.inTransaction in project hibernate-orm by hibernate.

the class JPAQLComplianceTest method testParameterCollectionParenthesesAndPositional.

@Test
@TestForIssue(jiraKey = "HHH-12290")
public void testParameterCollectionParenthesesAndPositional() {
    final Item item = new Item("Mouse");
    item.setId(1L);
    final Item item2 = new Item("Computer");
    item2.setId(2L);
    TransactionUtil2.inTransaction(sessionFactory(), s -> {
        s.save(item);
        s.save(item2);
    });
    TransactionUtil2.inTransaction(sessionFactory(), s -> {
        Query q = s.createQuery("select item from Item item where item.id in(?1) and item.name in (?2) and item.id in(?1)");
        List<Long> idParams = new ArrayList<>();
        idParams.add(item.getId());
        idParams.add(item2.getId());
        q.setParameter(1, idParams);
        List<String> nameParams = new ArrayList<>();
        nameParams.add(item.getName());
        nameParams.add(item2.getName());
        q.setParameter(2, nameParams);
        List result = q.getResultList();
        assertNotNull(result);
        assertEquals(2, result.size());
    });
    TransactionUtil2.inTransaction(sessionFactory(), s -> s.createQuery("from Item").list().forEach(result -> s.delete(result)));
}
Also used : Assert.assertNotNull(org.junit.Assert.assertNotNull) Session(org.hibernate.Session) Test(org.junit.Test) ArrayList(java.util.ArrayList) TransactionUtil2(org.hibernate.testing.transaction.TransactionUtil2) TestForIssue(org.hibernate.testing.TestForIssue) List(java.util.List) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) AbstractJPATest(org.hibernate.test.jpa.AbstractJPATest) Query(org.hibernate.query.Query) Assert.fail(org.junit.Assert.fail) Item(org.hibernate.test.jpa.Item) ExtraAssertions.assertTyping(org.hibernate.testing.junit4.ExtraAssertions.assertTyping) Assert.assertEquals(org.junit.Assert.assertEquals) Item(org.hibernate.test.jpa.Item) Query(org.hibernate.query.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) AbstractJPATest(org.hibernate.test.jpa.AbstractJPATest) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Session (org.hibernate.Session)1 QuerySyntaxException (org.hibernate.hql.internal.ast.QuerySyntaxException)1 Query (org.hibernate.query.Query)1 AbstractJPATest (org.hibernate.test.jpa.AbstractJPATest)1 Item (org.hibernate.test.jpa.Item)1 TestForIssue (org.hibernate.testing.TestForIssue)1 ExtraAssertions.assertTyping (org.hibernate.testing.junit4.ExtraAssertions.assertTyping)1 TransactionUtil2 (org.hibernate.testing.transaction.TransactionUtil2)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.fail (org.junit.Assert.fail)1 Test (org.junit.Test)1