|
44 | 44 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
45 | 45 |
|
46 | 46 | import static org.junit.Assert.assertEquals;
|
| 47 | +import static org.junit.Assert.assertTrue; |
47 | 48 |
|
48 | 49 | /**
|
49 | 50 | * @author Steve Ebersole
|
@@ -157,6 +158,49 @@ public void testFilteringJoinedSubclasses() {
|
157 | 158 | s.close();
|
158 | 159 | }
|
159 | 160 |
|
| 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 | + |
160 | 204 | @Entity( name = "JoinedEntity" )
|
161 | 205 | @Table( name = "JoinedEntity" )
|
162 | 206 | @Inheritance( strategy = InheritanceType.JOINED )
|
|
0 commit comments