I have a requirement to store histroy of message table. means I can create message or update message, when ever I create/update message, some records should also stroed in History table (means in update also , a new row should be insert in histroy)
I am trying to implement through one-to-many relation,as if we change name & subject i.e.two attributes,two row will be entered in history table ( many folks in this forum suggested to use bidirectional,that i have used even I require unidirectional)
the entry in hbm files are like
<?xml version="1.0"?>
<hibernate-mapping package="nl.inspiring.hibernate.test" default-access="field">
<class name="Message">
<id name="messageId">
<generator class="native"/>
</id>
<property name="name" column="name"/>
<property name="subject" column="sub"/>
<set name="histories" cascade="save-update" inverse="true"/>
<key column="messageId" />
<one-to-many class="History"/>
</set>
</class>
<class name="History">
<id name="historyId">
<generator class="native"/>
</id>
<property name="name" unique="true"/>
<many-to-one name="message" column="messageId" class="Message"/>
</class>
</hibernate-mapping>
If am using inverse true, in log only reuired no. of insert queries execute, but messageId comes null when records insert in Message, on update it is fine as I have that time messageId.
If I am not using inverse, along with insert update queries also executes, for first insert it working fine but for update new records properly inserted but the first record (which is edited now) modified with null in History table.
Any suggestion, how to deal with, if I want every time insert record in child on save or update inparent table (using one-to-many)
Thanks,
Raj
[ July 05, 2008: Message edited by: Rajan Nath ]
[ July 05, 2008: Message edited by: Rajan Nath ]
[ July 05, 2008: Message edited by: Rajan Nath ]