-->
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: By-directional many-to-many
PostPosted: Fri Jul 09, 2004 12:04 pm 
Newbie

Joined: Fri Jul 09, 2004 11:43 am
Posts: 2
Hi,

I need a little advice. I'm using version 2.1 of Hibernate.

I have 3 tables

ORDER
ORDER_SEQ (pk)
ORDER_ID
ORDER_NAME

ORDER_GRP_RLT
ORDER_SEQ (fk)
ORDER_GRP_SEQ (fk)

ORDER_GRP
ORDER_GRP_SEQ (pk)
TYPE


When I create an Order, I can create the OrderGrp using a <many-to-many> without any problem.

What I am having a problem with, is that I need to associate existing Orders to the Order group I just created.

Example:

Order
001
ID1
Order1

OO2
ID2
Order2

OrderGrpRlt
002
002

001 <---(This is the relationship back to order 1)
001

OrderGrp
001
TypeA

When I'm createing Order 2, I have to make the association to Order1 which is already in the DB.
How do I do this?

Thanks For you Help.
Chris...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 12:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hi, please take a look at the parent-child-relationship chapter of the docs. Just load the existing object and set up the references appropriately.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 11:43 am 
Newbie

Joined: Fri Jul 09, 2004 11:43 am
Posts: 2
I have setup the lists correctly.
Class A ---> Class B ---> Class C

Class A and C reference the same table and are related via 2 <many-to-many> relationships.

I'm able to insert the data correctly, but when I try to read the data, I get the following exception:

Caused by: net.sf.hibernate.WrongClassException: Object with id: 7559 was not of the specified subclass: com.level3.imagestore.persistence.wrapper.RelatedServiceOrderWrapper (loaded object was of wrong class)

After looking at:
net.sf.hibernate.engine.Key class, I would question the hashCode and equals implementation.

The point is that I should be able to reference the same table from as many different classes as I want.

Chris Kohle
Level(3) Communications.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 12, 2004 12:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You cannot have the same row associated to 2 instances in a single session at the same time.
Thus, you can map several classes on the same table but be aware that 1 row is loaded in only 1 class.

_________________
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.