-->
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.  [ 2 posts ] 
Author Message
 Post subject: DAO and domain model question
PostPosted: Mon Mar 13, 2006 4:48 am 
Newbie

Joined: Mon Mar 13, 2006 4:17 am
Posts: 4
I was reading Hibernate in Action and chapter 8 that describe the use of DAO objects and Commands.

I m new to all this so i have the following question. Let’s say i have a domain model with POJOS and DAO classes for each of this pojos that do all the data access work using hibernate. Lets now also assume that one of the classes of the domain model has a lot of collection associations with other classes (a lot of one to many relationships) and lets say that i use a Command class in order to get a list or maybe just one of this domain model pojo that has none of its collection associations initialized.

Why is it bad for the client (maybe a jsp page) that is fed with this particular pojo to lazy load any of the associated collection of this object using DAO objects inside the getters of these collections in order to load the collection from the database?

I know that is best to initialize before all the data that the client will need (using eager fetching strategies for the collections we need) but what if we don’t know what we will need. Is this practice using DAO inside getters too bad for performance??? (Maybe if we use a large list of objects and for each of the items we access some collection i understand that it is but if we use only one object how bad it is to use this DAO inside the getters to receive some of the collections ??)
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 6:54 am 
Newbie

Joined: Tue Mar 07, 2006 7:20 am
Posts: 16
You should remember that everything that you do is translated in SQL queries and you should eagerly fetch things if you know in advance that you are going to need them. Eager fetching causes Hibernate to create an SQL JOIN and fetch everything you need in one query.

It is slower if you have to run an extra query for every item in a collection, but tracing the sql might show you that as well...

Good luck!


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