-->
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.  [ 4 posts ] 
Author Message
 Post subject: many-to-many relationship with extra columns in join table
PostPosted: Tue Dec 23, 2003 7:47 pm 
Newbie

Joined: Tue Dec 23, 2003 7:37 pm
Posts: 2
I've read all the documentation and many of the forum postings and haven't found an answer to my problem.
I have a many-to-many relationship with the same table. Here is the mapping:

<class name="com.dotmarketing.beans.Inode" table="inode">
<id name="inode" column="inode" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">inode_seq</param>
</generator>
</id>
<property name="owner" type="int" />
<property name="iDate" type="java.util.Date" />
<property name="type" type="string" not-null="true" length="64" />

<set name="children" table="tree" lazy="true">
<key column="parent" />
<many-to-many class="com.dotmarketing.beans.Inode" column="child" />
</set>

<set name="parents" table="tree" inverse="true" lazy="true">
<key column="child" />
<many-to-many class="com.dotmarketing.beans.Inode" column="parent" />
</set>

My table tree has two attributes: child and parent. This works fine. I need to add Extra columns to Tree called relation_type and tree_order.

I did what the section 7.2 in the documentation says so now my mapping for the set looks like:

<set name="parents" inverse="true" lazy="true">
<key column="child" />
<composite-element class="com.dotmarketing.beans.Tree">
<property name="relationType" column="relation_type"/>
<property name="treeOrder" column="tree_order"/>
<many-to-one name="parent" column="parent" class="com.dotmarketing.beans.Inode" />
</composite-element>
</set>

and i get the error:
Relation parents doesn't exist
when I run a query refering to the size of the set it
size(inode.parents) it runs the following query on the db

(select count(*) from parents parents0_ where category.inode=parents0_.child)

and parents doesn't exist, it should be the table tree.

so i added the mapping for tree and i get the same error. here is the mapping:
<class name="com.dotmarketing.beans.Tree" table="tree">
<composite-id unsaved-value="any">
<key-many-to-one name="child" column="child" class="com.dotmarketing.beans.Inode" />
<key-many-to-one name="parent" column="parent" class="com.dotmarketing.beans.Inode" />
</composite-id>
<property name="relationType" column="relation_type" length="64" type="string"/>
<property name="treeOrder" column="tree_order" length="64" type="string"/>
</class>

any help would be greatly appreciated! :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 24, 2003 4:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Don't map Tree as a class, but add the table attribute
Code:
<set name="parents" inverse="true" lazy="true"table="tree">
<key column="child" />
<composite-element class="com.dotmarketing.beans.Tree">
<property name="relationType" column="relation_type"/>
<property name="treeOrder" column="tree_order"/>
<many-to-one name="parent" column="parent" class="com.dotmarketing.beans.Inode" />
</composite-element>
</set>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 24, 2003 9:38 am 
Newbie

Joined: Tue Dec 23, 2003 7:37 pm
Posts: 2
Emmanuel Thanks for your answer!

I did this and now it finds the table but when I make a query in hibernate like this:

Code:
where ? in inode.parents.elements


It tries to bring back all the items in tree like this:

Code:
where 1057 in (select parents0_.relation_type, parents0_.tree_order, parents0_.parent from tree parents0_ where folder.inode=parents0_.child)


and the query should be like:

Code:
where 1057 in (select parents0_.parent from tree parents0_ where folder.inode=parents0_.child)


using only the parent not the other two attributes.

is there any way I can tell it from inode.parent.elements that I only want the parent???

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 24, 2003 10:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try the last one
http://forum.hibernate.org/viewtopic.php?t=926652

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.