mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-06 19:36:03 +00:00
HHH-12290 - Failure with JPQL positional queries with collection parameter (IN statement for example)
This commit is contained in:
parent
4d9fb70114
commit
86da00d66f
@ -6,22 +6,24 @@
|
||||
*/
|
||||
package org.hibernate.test.jpa.ql;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.hql.internal.ast.QuerySyntaxException;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.transaction.TransactionUtil2;
|
||||
import org.hibernate.test.jpa.AbstractJPATest;
|
||||
import org.hibernate.test.jpa.Item;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests for various JPAQL compliance issues
|
||||
*
|
||||
@ -76,32 +78,69 @@ public void testOrderByAlias() {
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12290")
|
||||
public void testParametersMixturePositionalAndNamed() {
|
||||
Session s = openSession();
|
||||
TransactionUtil2.inTransaction(
|
||||
sessionFactory(),
|
||||
s -> {
|
||||
try {
|
||||
s.createQuery( "select item from Item item where item.id = ?1 and item.name = :name" ).list();
|
||||
fail( "Expecting QuerySyntaxException because of named and positional parameters mixture" );
|
||||
} catch ( IllegalArgumentException e ) {
|
||||
assertNotNull( e.getCause() );
|
||||
assertTyping( QuerySyntaxException.class, e.getCause() );
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12290")
|
||||
public void testParametersMixtureNamedAndPositional() {
|
||||
Session s = openSession();
|
||||
TransactionUtil2.inTransaction(
|
||||
sessionFactory(),
|
||||
s -> {
|
||||
try {
|
||||
s.createQuery( "select item from Item item where item.id = :id and item.name = ?1" ).list();
|
||||
fail( "Expecting QuerySyntaxException because of named and positional parameters mixture" );
|
||||
} catch ( IllegalArgumentException e ) {
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
assertNotNull( e.getCause() );
|
||||
assertTyping( QuerySyntaxException.class, e.getCause() );
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12290")
|
||||
public void testReusedNamedCollectionParam() {
|
||||
TransactionUtil2.inTransaction(
|
||||
sessionFactory(),
|
||||
session -> {
|
||||
Query q = session.createQuery( "select item from Item item where item.id in (:values) or item.name in (:values)" );
|
||||
List<Long> params = new ArrayList<>();
|
||||
params.add( 0L );
|
||||
params.add( 1L );
|
||||
q.setParameter( "values", params );
|
||||
q.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12290")
|
||||
public void testReusedPositionalCollectionParam() {
|
||||
TransactionUtil2.inTransaction(
|
||||
sessionFactory(),
|
||||
session -> {
|
||||
Query q = session.createQuery( "select item from Item item where item.id in (?1) or item.name in (?1)" );
|
||||
List<Long> params = new ArrayList<>();
|
||||
params.add( 0L );
|
||||
params.add( 1L );
|
||||
q.setParameter( 1, params );
|
||||
q.list();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Positional collection parameter is expanded to the list of named parameters. In spite of this fact, initial query
|
||||
@ -110,7 +149,9 @@ public void testParametersMixtureNamedAndPositional() {
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-12290")
|
||||
public void testParametersMixtureNamedCollectionAndPositional() {
|
||||
Session s = openSession();
|
||||
TransactionUtil2.inTransaction(
|
||||
sessionFactory(),
|
||||
s -> {
|
||||
try {
|
||||
Query q = s.createQuery( "select item from Item item where item.id in (?1) and item.name = :name" );
|
||||
List<Long> params = new ArrayList<>();
|
||||
@ -125,9 +166,8 @@ public void testParametersMixtureNamedCollectionAndPositional() {
|
||||
assertNotNull( e.getCause() );
|
||||
assertTyping( QuerySyntaxException.class, e.getCause() );
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user