-->
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: many-to-many between 2 objects but using 2 relational tables
PostPosted: Mon Nov 12, 2007 4:23 pm 
Newbie

Joined: Mon Nov 12, 2007 4:06 pm
Posts: 2
I have a somewhat complicated tree node structure that i'm trying to use hibernate for.

I have 2 objects, a TreeNode and a TreeNodeGroup, and a table for each. TreeNodes are pretty much what you expect, however, their children are not TreeNodes but TreeNodeGroups. Each TreeNode has 0..M TreeNodeGroups, and each TreeNodeGroup has 0..M TreeNodes.

The reason for doing this is that I want to group TreeNodes together in a group, and then use that group as children for any TreeNode.

In order to keep track of this relationship, I have 2 relational tables: A) for linking TreeNode -> TreeNodeGroups, and B) for linking TreeNodeGroup -> TreeNodes.

The entities are related to each other, but in two ways! The parent node -> child groups, and parent group -> child nodes.

My question is, how do I do the many-to-many associations in the hbm.xml?

I don't need to go backwards from the child -> parent, so I tried leaving out the inverse attribute, but I get JDBC commit errors on a get, which means that just by retrieving an object, Hibernate thinks it's been modified, so it tries to save it back to the DB and breaks some DB constraint, which throws an exception.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 12, 2007 7:13 pm 
Newbie

Joined: Mon Nov 12, 2007 4:06 pm
Posts: 2
Let me add some clarification:

I have 2 classes:
TreeNode and TreeNodeGroup.

TreeNode has a collection of TreeNodeGroup called childGroups.
TreeNodeGroup has a collection of TreeNode called childNodes.

TreeNode does NOT have a collection of TreeNodeGroup called parentGroups.
TreeNodeGroup does NOT have a collection of TreeNode called parentNodes.

I have 4 tables:
TreeNode, TreeNodeGroup, TreeNode_TreeNodeGroup, TreeNodeGroup_TreeNode

So, to sum up:

I have 2 classes which have a many-to-many relationship to each other. However, the m..m relationship is NOT bidirectional : the relationships only go one way, from the parent to the child. The classes are related using many-to-many, but they reference different relational tables.

The problem i'm running into is how do I represent this in the mapping metadata?


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.