/
InsertWithSubSelectTest.java
114 lines (94 loc) · 1.99 KB
/
InsertWithSubSelectTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.hql;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
/**
* @author bjoern.moritz
*/
@TestForIssue(jiraKey = "HHH-5274")
public class InsertWithSubSelectTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
A.class,
B.class,
C.class
};
}
@Test
public void testInsert() {
doInHibernate( this::sessionFactory, session -> {
session.createQuery(
"insert into C (id) " +
"select a.id from A a " +
"where exists (" +
" select 1 " +
" from B b " +
" where b.id = a.id" +
")"
)
.executeUpdate();
} );
}
@Test
public void testSelect() {
doInHibernate( this::sessionFactory, session -> {
session.createQuery(
"select a.id " +
"from A a " +
"where exists (" +
" select 1 " +
" from B b " +
" where b.id = a.id" +
")"
)
.getResultList();
} );
}
@Entity(name = "A")
public static class A {
@Id
@GeneratedValue
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
@Entity(name = "B")
public static class B {
@Id
@GeneratedValue
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
@Entity(name = "C")
public static class C {
@Id
@GeneratedValue
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
}