Skip to content

Commit 1ec7688

Browse files
committed
HHH-9862 : Multiple TREAT operators does not work properly for joined inheritance (test case)
1 parent dd57871 commit 1ec7688

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
@@ -27,6 +27,7 @@
2727
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
2828

2929
import static org.junit.Assert.assertEquals;
30+
import static org.junit.Assert.assertTrue;
3031

3132
/**
3233
* @author Steve Ebersole
@@ -140,6 +141,49 @@ public void testFilteringJoinedSubclasses() {
140141
s.close();
141142
}
142143

144+
@Test
145+
@TestForIssue( jiraKey = "HHH-9862" )
146+
@FailureExpected( jiraKey = "HHH-9862" )
147+
public void testRestrictionsOnJoinedSubclasses() {
148+
Session s = openSession();
149+
s.beginTransaction();
150+
JoinedEntity root = new JoinedEntity( 1, "root" );
151+
s.save( root );
152+
JoinedEntitySubclass child1 = new JoinedEntitySubclass( 2, "child1", root );
153+
s.save( child1 );
154+
JoinedEntitySubclass2 child2 = new JoinedEntitySubclass2( 3, "child2", root );
155+
s.save( child2 );
156+
s.getTransaction().commit();
157+
s.close();
158+
159+
s = openSession();
160+
s.beginTransaction();
161+
162+
List result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1'" ).list();
163+
assertEquals( 1, result.size() );
164+
assertTrue( JoinedEntitySubclass.class.isInstance( result.get( 0 ) ) );
165+
166+
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child1'" ).list();
167+
assertEquals( 0, result.size() );
168+
169+
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child2'" ).list();
170+
assertEquals( 1, result.size() );
171+
assertTrue( JoinedEntitySubclass2.class.isInstance( result.get( 0 ) ) );
172+
173+
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1' or treat (e as JoinedEntitySubclass2 ).name = 'child2'" ).list();
174+
assertEquals( 2, result.size() );
175+
176+
s.close();
177+
178+
s = openSession();
179+
s.beginTransaction();
180+
s.delete( child1 );
181+
s.delete( child2 );
182+
s.delete( root );
183+
s.getTransaction().commit();
184+
s.close();
185+
}
186+
143187
@Entity( name = "JoinedEntity" )
144188
@Table( name = "JoinedEntity" )
145189
@Inheritance( strategy = InheritanceType.JOINED )

0 commit comments

Comments
 (0)