HI
I use hibernate3 and xdoclet1.2.3.
there are four classes.(user,group,actor,role)
user extends actor
group extends actor
actor and role is many-to-many relation.
This is the actor.hbm.xml mapping file that generated by xdoclet1.2.3:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="com.test.Actor" table="u_actor">
<id
name="id"
column="actor_id"
type="java.lang.Long"
length="10"
>
<generator class="hilo">
<param name="table">IdTable</param>
<param name="column">nextId</param>
<param name="max_lo">99</param>
</generator>
</id>
<set
name="roles"
table="u_actor_role"
lazy="false"
inverse="false"
cascade="save-update"
sort="unsorted"
>
<key
column="actor_id"
>
</key>
<many-to-many
class="com.test.Role"
column="role_id"
outer-join="auto"
/>
</set>
<joined-subclass
name="com.test.User"
table="u_user"
>
<key
column="user_id"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
not-null="true"
unique="true"
/>
</joined-subclass>
<joined-subclass
name="com.test.Group"
table="u_group"
>
<key
column="group_id"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
not-null="true"
unique="true"
/>
</joined-subclass>
</class>
</hibernate-mapping>
This is role.hbm.xml mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class
name="com.test.Role"
table="u_role"
>
<id
name="id"
column="role_id"
type="java.lang.Long"
length="10"
>
<generator class="hilo">
<param name="table">IdTable</param>
<param name="column">nextId</param>
<param name="max_lo">99</param>
</generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>
<set
name="users"
table="u_actor_role"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
>
<key
column="role_id"
>
</key>
<many-to-many
class="com.test.User"
column="actor_id"
outer-join="auto"
/>
</set>
<set
name="groups"
table="u_actor_role"
lazy="true"
inverse="true"
cascade="save-update"
sort="unsorted"
>
<key
column="role_id"
>
</key>
<many-to-many
class="com.test.Group"
column="actor_id"
outer-join="auto"
/>
</set>
</class>
</hibernate-mapping>
so when i use hibernate3's tool schemaexport to generate database, the table u_actor_role will generate four FKs(user_id,group_id,actor_id,role_id).
when execute follow code,it will cause problem:org.hibernate.exception.ConstraintViolationException: could not insert:
Code:
User u = new User();
Role r = new Role();
u.add(r);
r.add(u);
session.saveOrUpdate(u);
when i use hibernate2's tool schemaexport to generate database, the table u_actor_role will generate two FKs(actor_id,role_id). and it executes above code successfully.