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
|