-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: joined-subclass 's problem
PostPosted: Tue Aug 02, 2005 6:22 am 
Newbie

Joined: Tue Aug 02, 2005 2:51 am
Posts: 2
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 8:39 pm 
Newbie

Joined: Tue Aug 02, 2005 2:51 am
Posts: 2
who can tell me why?
thanks !


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.