-->
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.  [ 3 posts ] 
Author Message
 Post subject: Question about the efficiency of Cascading
PostPosted: Wed Jan 11, 2006 4:46 am 
Newbie

Joined: Tue Jan 04, 2005 4:05 am
Posts: 8
Dear friends,

Since I am new to Hibernate, I am trying to explore the benefits of using it, definitely it is very useful and very state-of-the-art solution.

I only have one doubt, which I believe it is not very effective in some cases where the data can be in huge numbers.

For example, suppose I have "Event" entity, and there are dozens of "Speakers" who will deliver a speech in this Event. The solution of course is the association. So the code for adding a speaker to an event is :

Speaker newSpeaker=.......

Event event=(Event)sess.load(Event.class,.........
event.getSpeakers().add(newSpeaker);

Ok, assuming that the lazy=true in the association between events and speakers, the Hibernate will do the following if we traced the generated SQLs:

1. Loads and event
2. loads all the speakers associated with this event (due to getSpeakers() calling)
3. adds the new speaker to the table

Now, suppose I have 1000 speakers in an event, is it necessary for Hibernate to load all those 1000 speakers in order to add another speaker ? loading 1000 speakers is an expensive price for adding one speaker
only

I know that I can go straight to the speaker Entity and assign the eventId manually, but I am trying to explore the benefits of Hibernate and the best practices for such cases.

Please advise.

Thank you very much
Zaid


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 6:24 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello zaid,
When you call event.getspeaker.add Hibernate will have to look at all Speakers to know if the value is allready contained.

you may manage the event from the other side. so do not create a event.getSpeaker method.
When you need both information you can use a query.
"from Event e, Speaker s where s.event=e"
this will return a list of arrays holding your values. See the reference for this queries.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject: Hey Sebastian
PostPosted: Wed Jan 11, 2006 9:34 am 
Newbie

Joined: Tue Jan 04, 2005 4:05 am
Posts: 8
You are the king of the Tutorials man !!, I've read most of your tutorials on your website and I am a regular visitor. God bless you.

Yes, you mean creating Speaker and assign the eventId manually, in other words create the speaker and attachs it to the related event.

Thank you very much for trying to help me.

Yours,
Zaid


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