There are four types A, B, B, B1, B2, B1, B2 inheritance B, A and B1, B2 are
//B.javapublic Abstract Class B {Private Integer ID; Private A A;
//B1.javapublic class b1 extends b {}
//B2.javapublic class b2 extends b {}
Hibernate mapping file is: XML Version = "1.0" encoding = "UTF-8"?>
Use the Hibernate SchemauPdate to generate a table and insert the data of the following structure: Table: A ID1 table: B id b_type a_id 1 1 1 2 2 1
Then the A object of select id = 1, hibernate throws an exception: net.sf.hibernate.wrongClassexception: Object with ID: 1 WAS NOT OF TESER SPECified Subclass: Test.b2 (Loaded Object Was of Wrong Class) seems to be Hiberate The two records of id = 1 and ID = 2 are treated as an object (either B1, either b2), in this case, Hibernate is fully capable (only the type in the WHERE statement ) Distinguish our object is B1 or B2, don't know if this is not a bug of hibernate?
Workaround: Method 1: Spread A to B1, B2