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: Can't do a very simple mapping
PostPosted: Thu Aug 16, 2007 8:29 am 
Beginner
Beginner

Joined: Mon Jul 30, 2007 4:58 pm
Posts: 21
Hello, here's my case:

According to my domain model:
A School has many Students. and the relation is unidirectional

However when I use Set, adding a new student to a school causes entire students to be loaded.

If there are 1 million students, that's a big problem. In this sense , Sets are useless to me.

Using a bag is also useless. It is pretty troublesome if inverse = false and you add an item to your bag since it would truncate your table

Using and idbag is not possible. I've never seen a one-to-many mapping with idbag ?

So what to do ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 16, 2007 9:44 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
save the new student manually, if you don't need the object relationship immediately.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 16, 2007 11:10 am 
Newbie

Joined: Wed Aug 15, 2007 3:50 pm
Posts: 6
Location: Philadelphia
1) Save the Student object by itself,
2) and manually add the object to the School instance if you need it later to be part of School's set.

To avoid loading all 1mil Students automatically when you retrieve School, remember to declare in School.hbm.xml that its Student set is lazy.
Then it won't load all the Students until you explicitly call Hibernate.initialize().


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 16, 2007 11:11 am 
Newbie

Joined: Wed Aug 15, 2007 3:50 pm
Posts: 6
Location: Philadelphia
1) Save the Student object by itself,
2) and manually add the object to the School instance if you need it later to be part of School's set.

To avoid loading all 1mil Students automatically when you retrieve School, remember to declare in School.hbm.xml that its Student set is lazy.
Then it won't load all the Students until you explicitly call Hibernate.initialize().


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.