Hi all,
First, my hibernate mapping file:
Code:
<hibernate-mapping>
<class name='eg.SystemMessage' table='SystemMailbox'>
<id name='message_id' type='int' column='message_id' unsaved-value='-1'>
<generator class='sequence'>
<param name='sequence'>SEQ_MSGTOOL_MSGID</param>
</generator>
</id>
<property name='sender' column='sender' type='string' unique='false' not-null='true'/>
<property name='subject' column='subject' type='string' unique='false' not-null='true'/>
<property name='body' column='body' type='string' unique='false' not-null='true'/>
<property name='publish_date' column='publish_date' type='date' unique='false' not-null='true'/>
<set name='receivers'
lazy='true'
inverse='true'
cascade='all'>
<key column='message_id'/>
<one-to-many class='eg.UserAccountMessage'/>
</set>
</class>
<class name='eg.UserAccountMessage' table='OwnUserMailbox'>
<composite-id>
<key-property name='user_id' column='user_id' type='string'/>
<key-many-to-one name='message' class='eg.SystemMessage'>
<column name='message_id'/>
</key-many-to-one>
</composite-id>
<property name='scope' column='scope' type='string' unique='false' not-null='true'/>
<property name='scope_id' column='scope_id' type='string' unique='false' not-null='false'/>
<property name='visited' column='visited' type='integer' unique='false' not-null='false'/>
</class>
</hibernate-mapping>
And my java code:
Code:
SystemMessage msg = new SystemMessage();
msg.setBody("The message body");
msg.setMessage_id(-1);
msg.setPublish_date(new Date(System.currentTimeMillis()));
msg.setSender("the_sender");
msg.setSubject("Message subject");
UserAccountMessage umsg = new UserAccountMessage();
umsg.setScope("system");
umsg.setUser_id("user2");
umsg.setMessage(msg);
UserAccountMessage umsg_1 = new UserAccountMessage();
umsg_1.setScope("system");
umsg_1.setUser_id("user1");
umsg_1.setMessage(msg);
msg.getReceivers().add(umsg);
msg.getReceivers().add(umsg_1);
Session session = access.getSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
//
session.save(msg);
/*At this point msg is saved, but the content of receivers is not saved*/
session.flush();
tx.commit();
}catch (HibernateException he) {
....
}
And finally the problem.
When the statement session.save() is executed the info for SystemMailbox table is saved correctly (variable msg), but hibernate doesn't save the UserAccountMessage info (the content of attribute receivers in the variable msg).
Any ideas??
Thanks in advance,
[/code]