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: HQL Query not honoring mapping file
PostPosted: Wed Sep 01, 2010 12:05 pm 
Newbie

Joined: Wed Sep 01, 2010 11:22 am
Posts: 2
Hello,

I've ran a basic test with NHibernate comparing criteria vs hql. Here's my criteria call:
Code:
sessionFactory.GetCurrentSession().CreateCriteria<User>().List<User>();

If I retrieve the entity with a criteria query, it executes only a single query, retrieving the entity and all it's mapped many-to-ones in a single query.
Code:
sessionFactory.GetCurrentSession().CreateQuery("from User").List<User>();

This HQL query will get the same list, but it makes several queries to the database, one for the list of users and then more for retrieving individual objects mapped as many-to-ones in the User mappings file.

Is a HQL query suppose to ignore an entity's mapping file? Is there a way to make it honor the mapping file or do I have to include a bunch of join fetches for every HQL statement?

Sorry if this was answered somewhere in the documentation, but I couldn't find it.

_________________
Thanks,
Jeffrey Jochum


Top
 Profile  
 
 Post subject: Re: HQL Query not honoring mapping file
PostPosted: Thu Sep 02, 2010 2:52 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
you need to "fetch" the association: "from User u join fetch u.Whatever"

_________________
--Wolfgang


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.