-->
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.  [ 5 posts ] 
Author Message
 Post subject: Many-to-many relation
PostPosted: Wed Aug 01, 2007 2:52 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 11:11 am
Posts: 24
Location: India
Hibernate version: 3.2.4.sp1

Hi,
I'm trying to build a many-to-many relation between Person and Address, both having a set inside.
In the hbm file i made inverse= true for Address.
This works fine in case of saving data. But i'm getting a StackOverFlowException when i'm trying to load either of the entity.

How to solve this problem?

Regards,
Supriyo


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 01, 2007 3:21 am 
Beginner
Beginner

Joined: Sat Jan 14, 2006 10:05 am
Posts: 22
Location: spb.ru
please show the code


Top
 Profile  
 
 Post subject: Many-to-many relation
PostPosted: Thu Aug 02, 2007 1:52 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 11:11 am
Posts: 24
Location: India
Mapping :
<class name="Person">
.......
<set name="address" table name="PERSON_ADDRESS">
<key column="PERSON_ID"/>
<many-to-many column="ADD_ID" class="Addres"/>
</set>


<class name="Addres">
.......
<set name="persons" table name="PERSON_ADDRESS" inverse="true">
<key column="ADD_ID"/>
<many-to-many column="PERSON_ID" class="Person"/>
</set>

Java code:

session.save( new Person(.....)); //working
session.load( Person.class, personId); // Not working

At the time of loading it is giving StackOverflowException.
Is there any option to get rid of this???

Supriyo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 4:08 am 
Newbie

Joined: Thu Aug 02, 2007 2:28 am
Posts: 1
you are committing a common mistake.

The reason is that with every Person, n Address objects are loaded and with every Address object, m Persons are loaded. This is a cycle which eventually crashes the JVM.

Use an association table for this purpose. and make your associations lazy loaded.

This should solve the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 2:35 am 
Beginner
Beginner

Joined: Thu Feb 08, 2007 11:11 am
Posts: 24
Location: India
venkata sankara wrote:
you are committing a common mistake.

The reason is that with every Person, n Address objects are loaded and with every Address object, m Persons are loaded. This is a cycle which eventually crashes the JVM.

Use an association table for this purpose. and make your associations lazy loaded.

This should solve the problem.


Thanks dude,
I did overwrite the toString methods of those classes, from where the problem started.
again thanx a lot.


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