Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0.5
Mapping documents:
Code:
<class name="domain.Group" table="contact_group">
...
<set
name="contacts"
table="group_contact_mapping"
lazy="false"
inverse="false"
cascade="save-update"
sort="unsorted">
<key column="contact_group_id" />
<many-to-many
class="domain.Contact"
column="contact_id"
outer-join="auto"/>
</set>
</class>
Code between sessionFactory.openSession() and session.close():Code:
Contact phil = new Contact();
phil.setFirstName("Phil");
Group group1 = new Group("Group One");
group1.getContacts().add(phil);
session.save(group1);
Full stack trace of any exception that occurs:
None
Name and version of the database you are using:
HSQLDB 1.8.0
The generated SQL (show_sql=true):
Hibernate: insert into contact_group (name, id) values (?, null)
Hibernate: call identity()
Hibernate: insert into contact (first_name, id) values (?, null)
Hibernate: call identity()
Debug level Hibernate log excerpt:
There are no exceptions. The group and contact are saved to the database correctly. However the group_contact_mapping table is not updated with the many-to-many mapping. So when the group is retrieved, the contact is not retrieved. I must be doing something dumb, but I can't seem to track it down.