|
27 | 27 | import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
28 | 28 |
|
29 | 29 | import static org.junit.Assert.assertEquals;
|
| 30 | +import static org.junit.Assert.assertTrue; |
30 | 31 |
|
31 | 32 | /**
|
32 | 33 | * @author Steve Ebersole
|
@@ -140,6 +141,49 @@ public void testFilteringJoinedSubclasses() {
|
140 | 141 | s.close();
|
141 | 142 | }
|
142 | 143 |
|
| 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 | + |
143 | 187 | @Entity( name = "JoinedEntity" )
|
144 | 188 | @Table( name = "JoinedEntity" )
|
145 | 189 | @Inheritance( strategy = InheritanceType.JOINED )
|
|
0 commit comments