Hi,
I'm wondering what's the best way to handle transient properties of persisted object.
I have a persisted class, User, where one attribute is not saved in the database so is not in the hibernate mapping file. User is also in a many-to-one association with Group. If I retrieve the User in one session (say user1) and the Group with its User in another session (user2), all the persisted attributes are the same even though they are not the same object reference (as discussed in sec 2.2 of the ref manual).
I can use onLoad() to initialize the transient property, but if I make change to transient attribute in user1, the change is not reflected user2.
Is there a way that I can map the transient property so that Hiberante handles it across sessions the same way as the persisted properties without actually persisting it the DB?
I was wondering if others have encountered this & how they are addressing it.
Thanks in advance!
Linda :)
Code:
Group.hmb.xml
<hibernate-mapping>
<class name="eg.Group"
table="group">
<id name="id"
column="id"
type ="long"
unsaved-value="-1">
<generator class="native"/>
</id>
<property name="name"
column ="name"
type ="string"
length ="25"
not-null="true"
unique ="true"
/>
<many-to-one
name ="adminUser"
column="adminUser"
class ="eg.User"
/>
</class>
</hibernate-mapping>
User.hbm.xml
<hibernate-mapping>
<class name="eg.User"
table="user" >
<id name="id"
column="id"
type ="long"
unsaved-value="-1">
<generator class="native"/>
</id>
<property name ="name"
column ="name"
type ="string"
length ="25"
not-null ="true"
unique ="true"
/>
<!-- this is the transient property
I'd like to do something like this,
but a column "tmp" is expected
<property name ="tmp"
type ="string"
insert ="false"
update ="false"
/>
-->
</class>
</hibernate-mapping>