i'm making a simple helpdesk ticket application as a means of learning hibernate and other technologies and generally driving myself mad...
right now i can create a Ticket, which has a Set of related Tags. a Ticket can have 0..* Tags and vice-versa. i've modeled this in the database by means of a join table with ticket_id and tag_id
the problem i'm having is that when i create tickets with tags, the tickets and tags are saved in their respective tables but the join table is not populated, apparently since there is no Ticket.id when i call save(). if i modify an existing ticket the join table IS updated.
the order of operations is thus:
create Ticket, populate data
create Tags, add to Ticket
save Tags
save Ticket
i've also tried
create Ticket, populate datas
save Ticket
create Tags, add to Ticket
save Tag
both with the same result: join table is not updated.
any ideas?
Hibernate version: 3.1rc2
Mapping documents:
Code:
Ticket:
<?xml version="1.0"?>
<!DOCTYPE
hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.jeffemminger.tracker.model.Ticket" table="tickets">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="title" type="string">
<column name="title" not-null="true"/>
</property>
<property name="description" type="string">
<column name="description" not-null="true"/>
</property>
<many-to-one name="owner" column="owner_user_id"
class="com.jeffemminger.tracker.model.User" not-null="true"/>
<set name="tags" table="tags_tickets" lazy="true" inverse="true"
cascade="save-update">
<key column="ticket_id"/>
<many-to-many class="com.jeffemminger.tracker.model.Tag"
column="tag_id"/>
</set>
</class>
</hibernate-mapping>
Tag:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.jeffemminger.tracker.model.Tag" table="tags">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="name" not-null="true"/>
</property>
<set name="tickets" table="tags_tickets" lazy="true" inverse="true"
cascade="save-update">
<key column="tag_id"/>
<many-to-many class="com.jeffemminger.tracker.model.Ticket"
column="ticket_id"/>
</set>
</class>
</hibernate-mapping>
Name and version of the database you are using: mysql 4.0.22
The generated SQL (show_sql=true):
Hibernate: insert into tags (name, created_on, updated_on) values (?, ?, ?)
Hibernate: insert into tickets (title, description, created_on, updated_on, owner_user_id) values (?, ?, ?, ?, ?)