-->
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: Not initializing one-to-one associations with Criteria query
PostPosted: Tue Oct 26, 2004 4:33 pm 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
I have the following situation:

Code:
Bank.address (n:1)
             (1:1) Address.bank
                   Address.country (n:1)
                                   (1:1) Country.address


My query looks like this:
Code:
Criteria c = session.createCriteria(Bank.class);
c.setFetchMode("address.country", FetchMode.EAGER);
c.list();


The problem is that the Address-Object has two additional 1:1 associations which must be loaded by Hibernate in order to initialize an instance of Address. That's pretty stupid for a query, resulting in (n*2)+1 queries.

Is there any way how I can achieve the same result *without* the number of 'post-processing'-queries ?

I just want the Bank, the Address and the Country. Everything else can be null without any problem.

I tried to add additional path elements to setFetchMode, but it seems that they were ignored (strangely I can type whatever I want in the path, no errors, it's just ignored).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 28, 2004 7:09 am 
Beginner
Beginner

Joined: Tue Aug 17, 2004 5:06 am
Posts: 46
My solution was that I switched from the Criteria-API to HQL queries.

Everything works fine.

My 2 cents: although it might look nice at the beginnning avoid the Criteria-API and use HQL-queries.


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.