-->
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: Should I use HQL queries or getters for fetching data?
PostPosted: Tue Feb 06, 2007 8:23 am 
Beginner
Beginner

Joined: Wed Jan 31, 2007 6:54 am
Posts: 22
Hibernate version:
3.2.2

Hi,
if I have a table Parent with PK ParentID, and want to get all of its Children (ParentID FK), what is the recommended approach for getting its children?

* Object navigation, something like:

Parent parent = (Parent)session.load(Parent.class, 1);
Set<Child> children = parent.getChildren();

* or through HQL:

session.createQuery("from Children where ParentID = 1").list()

Are there any performance issues with any of the approaches? Or is it simply a matter of taste?

The first seems more elegant, but if I dont need the Parent in the first place, its also one line of code more as well as more fetching from DB.

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 11:27 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
the performance differences would be unnoticable. It's a matter of taste. I like using session.load commands whenever possible. But I have plenty of queries that use hql in order to accomodate additional parameters.

_________________
Chris

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


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.