Ihor Herasymenko / Pedro, Based on the information provided, I used the existing discriminator test suite in hibernate-core, org.hibernate.test.discriminator, since the inheritance example mimics this issue perfectly. I made sure the mapping file used the PartTimeEmployee entity class, which was commented out and added the following test case. Your A entity is Person, B is Employee, C is Customer, and D is PartTimeEmployee.
@TestForIssue(jiraKey = "HHH-9311")
public void testDiscriminatorSubclassQueryBySuperType() {
Session s = openSession();
Transaction t = s.beginTransaction();
PartTimeEmployee chris = new PartTimeEmployee();
chris.setId( 1 );
chris.setName( "Chris" );
chris.setTitle( "engineer" );
chris.setSex( 'M' );
chris.setPercent( 60 );
s.save( chris );
assertEquals( s.createQuery( "from org.hibernate.test.discriminator.Person" ).list().size(), 1 );
assertEquals( s.createQuery( "from org.hibernate.test.discriminator.Person p where p.class = org.hibernate.test.discriminator.Person" ).list().size(), 1 );
assertEquals( s.createQuery( "from org.hibernate.test.discriminator.Person p where p.class = org.hibernate.test.discriminator.PartTimeEmployee" ).list().size(), 1 );
s.clear();
chris = (PartTimeEmployee) s.get( Employee.class, chris.getId() );
assertNotNull( chris );
s.delete( chris );
assertEquals( s.createQuery( "from.org.hibernate.test.discriminator.Person" ).list().size(), 0 );
t.commit();
s.close();
}
Based on the above, I cannot reproduce this in either branch 5.0 or 5.1. Ihor Herasymenko, since you said you could reproduce this in ORM5, can you confirm whether you were attempting to query the hierarchy the same way as I did? |