HHH-9862 : Multiple TREAT operators does not work properly for joined inheritance (test case)
This commit is contained in:
parent
dd57871cdb
commit
1ec7688782
|
@ -27,6 +27,7 @@ import org.hibernate.testing.TestForIssue;
|
|||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -140,6 +141,49 @@ public class TreatKeywordTest extends BaseCoreFunctionalTestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9862" )
|
||||
@FailureExpected( jiraKey = "HHH-9862" )
|
||||
public void testRestrictionsOnJoinedSubclasses() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
JoinedEntity root = new JoinedEntity( 1, "root" );
|
||||
s.save( root );
|
||||
JoinedEntitySubclass child1 = new JoinedEntitySubclass( 2, "child1", root );
|
||||
s.save( child1 );
|
||||
JoinedEntitySubclass2 child2 = new JoinedEntitySubclass2( 3, "child2", root );
|
||||
s.save( child2 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
|
||||
List result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1'" ).list();
|
||||
assertEquals( 1, result.size() );
|
||||
assertTrue( JoinedEntitySubclass.class.isInstance( result.get( 0 ) ) );
|
||||
|
||||
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child1'" ).list();
|
||||
assertEquals( 0, result.size() );
|
||||
|
||||
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass2 ).name = 'child2'" ).list();
|
||||
assertEquals( 1, result.size() );
|
||||
assertTrue( JoinedEntitySubclass2.class.isInstance( result.get( 0 ) ) );
|
||||
|
||||
result = s.createQuery( "select e from JoinedEntity e where treat (e as JoinedEntitySubclass ).name = 'child1' or treat (e as JoinedEntitySubclass2 ).name = 'child2'" ).list();
|
||||
assertEquals( 2, result.size() );
|
||||
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.delete( child1 );
|
||||
s.delete( child2 );
|
||||
s.delete( root );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Entity( name = "JoinedEntity" )
|
||||
@Table( name = "JoinedEntity" )
|
||||
@Inheritance( strategy = InheritanceType.JOINED )
|
||||
|
|
Loading…
Reference in New Issue