Skip to content

Commit 125aa7e

Browse files
quaffbeikov
authored andcommitted
HHH-18027 Test mutation query reuse with parameter list expansions
1 parent 2d7f384 commit 125aa7e

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.hibernate.orm.test.jpa.query;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.Id;
6+
import jakarta.persistence.Query;
7+
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
8+
import org.hibernate.testing.orm.junit.JiraKey;
9+
import org.hibernate.testing.orm.junit.Jpa;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.util.Set;
13+
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
16+
/**
17+
* @author Yanming Zhou
18+
*/
19+
20+
@Jpa(annotatedClasses = ReuseQueryWithExpandedParameterTest.Person.class)
21+
@JiraKey("HHH-18027")
22+
public class ReuseQueryWithExpandedParameterTest {
23+
24+
@Test
25+
public void reuseQueryWithExpandedParameter(EntityManagerFactoryScope scope) {
26+
scope.inTransaction( em -> {
27+
Person a = new Person( "a" );
28+
em.persist( a );
29+
Person b = new Person( "b" );
30+
em.persist( b );
31+
Person c = new Person( "c" );
32+
em.persist( c );
33+
Person d = new Person( "d" );
34+
em.persist( d );
35+
36+
Query q = em.createQuery( "from Person where name in (:names)" );
37+
assertEquals( 2, q.setParameter( "names", Set.of( "a", "b" ) ).getResultList().size() );
38+
assertEquals( 2, q.setParameter( "names", Set.of( "c", "d" ) ).getResultList().size() );
39+
40+
q = em.createQuery( "delete from Person where name in (:names)" );
41+
assertEquals( 2, q.setParameter( "names", Set.of( "a", "b" ) ).executeUpdate() );
42+
assertEquals( 2, q.setParameter( "names", Set.of( "c", "d" ) ).executeUpdate() );
43+
} );
44+
}
45+
46+
@Entity(name = "Person")
47+
public static class Person {
48+
@Id
49+
@GeneratedValue
50+
private Long id;
51+
52+
private String name;
53+
54+
public Person() {
55+
}
56+
57+
public Person(String name) {
58+
this.name = name;
59+
}
60+
61+
public Long getId() {
62+
return id;
63+
}
64+
65+
public void setId(Long id) {
66+
this.id = id;
67+
}
68+
69+
public String getName() {
70+
return name;
71+
}
72+
73+
public void setName(String name) {
74+
this.name = name;
75+
}
76+
}
77+
78+
}
79+

0 commit comments

Comments
 (0)