I have a hierarchy: User <-- Applicant <-- Member. I use table-per-class-hierarchy to implement this hierarchy of classes in my mapping file, user.hbm.xml.
Code:
<class name="User" table="`user`" lazy="true" abstract="true" discriminator-value="U">
<discriminator column="type" type="java.lang.String" not-null="true" length="1" insert="false"/>
<property name="type" type="java.lang.Character" not-null="true"/>
...
<subclass name="Applicant" discriminator-value="A">
<subclass name="Member" discriminator-value="M" >
</subclass>
</subclass>
</class>
At some point in my application, I change the type of User from Applicant to Member by callling
Code:
setType("M")
, follow by some other initilization. This change and initialization are wrapped inside a transaction. My problem is that, after changing the discriminator value of Applicant, and flush it explicitly, I can't retrieve the object for type Member, which I want to use it to set member specific values. I know the fact that hibernate implements something called a transaction scope identify which causes this problem, but how do I fix this? I can solve it by changing the discriminator value in one transaction, and initialization in another, but I want them to be in one instead of two transactions.
Any advice is appreciated.