Skip to content

Commit 66c193f

Browse files
committed
HHH-9862 : Multiple TREAT operators does not work properly for joined inheritance (test case)
(cherry picked from commit 1ec7688)
1 parent c37a879 commit 66c193f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

hibernate-core/src/test/java/org/hibernate/test/jpa/ql/TreatKeywordTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
4545

4646
import static org.junit.Assert.assertEquals;
47+
import static org.junit.Assert.assertTrue;
4748

4849
/**
4950
* @author Steve Ebersole
@@ -157,6 +158,49 @@ public void testFilteringJoinedSubclasses() {
157158
s.close();
158159
}
159160

161+
@Test
162+
@TestForIssue( jiraKey = "HHH-9862" )
163+
@FailureExpected( jiraKey = "HHH-9862" )
164+
public void testRestrictionsOnJoinedSubclasses() {
165+
Session s = openSession();
166+
s.beginTransaction();
167+
JoinedEntity root = new JoinedEntity( 1, "root" );
168+
s.save( root );
169+
JoinedEntitySubclass child1 = new JoinedEntitySubclass( 2, "child1", root );
170+
s.save( child1 );
171+
JoinedEntitySubclass2 child2 = new JoinedEntitySubclass2( 3, "child2", root );
172+
s.save( child2 );
173+
s.getTransaction().commit();
174+
s.close();
175+
176+
s = openSession();
177+
s.beginTransaction();
178+
179+
List result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1'" ).list();
180+
assertEquals( 1, result.size() );
181+
assertTrue( JoinedEntitySubclass.class.isInstance( result.get( 0 ) ) );
182+
183+
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child1'" ).list();
184+
assertEquals( 0, result.size() );
185+
186+
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child2'" ).list();
187+
assertEquals( 1, result.size() );
188+
assertTrue( JoinedEntitySubclass2.class.isInstance( result.get( 0 ) ) );
189+
190+
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1' or treat (e as JoinedEntitySubclass2 ).name = 'child2'" ).list();
191+
assertEquals( 2, result.size() );
192+
193+
s.close();
194+
195+
s = openSession();
196+
s.beginTransaction();
197+
s.delete( child1 );
198+
s.delete( child2 );
199+
s.delete( root );
200+
s.getTransaction().commit();
201+
s.close();
202+
}
203+
160204
@Entity( name = "JoinedEntity" )
161205
@Table( name = "JoinedEntity" )
162206
@Inheritance( strategy = InheritanceType.JOINED )

0 commit comments

Comments
 (0)