i have a situation like
UserAccount has one to many relationship to Introducers , Nominee etc
and also one to one relationship to AccountDetail which is an abstract class .
AccountDetails has two subclasses SavingDetail and CheckingDetail
i am getting a casting exception when i try to load using session.load(). it works fine when using session.get()
someone please provide me an explanation
Hibernate version:
3.1
Mapping documents:
<hibernate-mapping package="test">
<class name="AccountDetails" table="acct_details" abstract="true">
<id name="id" column="ACC_DTEAIL_ID" type="long" unsaved-value="null">
<generator class="sequence">
<param name="sequence">acct_details_counter</param>
</generator>
</id>
<many-to-one name="account" class="UserAccount" unique="true"></many-to-one>
<joined-subclass name="SavingAccountDetails" table="acct_details_sb" extends="AccountDetails">
<key column="ACC_DETAIL_ID"></key>
<many-to-one name="introducer" class="test.AcctIntroducer" unique="false" cascade="save-update"></many-to-one>
<set name="nominees" cascade="save-update">
<key column="ACC_DETAIL_ID"></key>
<one-to-many class="test.AcctNominee"/>
</set>
<set name="operators" cascade="save-update">
<key column="ACC_DETAIL_ID"></key>
<one-to-many class="test.AcctOperator"/>
</set>
</joined-subclass>
<jonied-subclass /> //for checking detail
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
Session session = factory.openSession();
try {
Transaction t = session.beginTransaction();
SavingAccountDetails accountDetails = (SavingAccountDetails) session.load(AccountDetails.class, 16L);
System.out.println(accountDetails);
t.commit();
} catch (Exception e) {
e.printStackTrace();
}finally {
session.close();
}
Full stack trace of any exception that occurs:
java.lang.ClassCastException: test.AccountDetails$$EnhancerByCGLIB$$fa33619f
at test.AccountDetailsTest.main(AccountDetailsTest.java:26)
Name and version of the database you are using:
PostgreSQL 7.4