-->
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.  [ 11 posts ] 
Author Message
 Post subject: JQL - does it overide fetch?
PostPosted: Wed May 28, 2008 3:11 pm 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
Hey,

I have the following relation:
Code:
@Entity
public class UserEntity {
...
@OneToOne(cascade = { CascadeType.ALL})
Address add = new Address();
...
}


I have the following query:
Code:
select userE from UserEntity as userE


When i do the query, i want to override the mapping (eager/lazy), but what I see is that it run one select for all user and for each user it run individual select to get the address.
In this case the relation is eager (I am working with JPA above Hibernate and OneToOne default is eager) , so when it load User it also load Address and it does it for each user.
I want in query to get the control on the fetching; I don’t want to bring objects, which weren’t defined explicitly in the query.

Is there a way to do this?

Thank you


Top
 Profile  
 
 Post subject: Re: JQL - does it overide fetch?
PostPosted: Wed May 28, 2008 3:28 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
How about:


Code:
select userE from UserEntity as userE inner join fetch userE.add




Farzad-


Top
 Profile  
 
 Post subject: I dont want to get the addresses
PostPosted: Wed May 28, 2008 3:40 pm 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
As i show the relation is eager, but in the query i want to override the mapping and get users without address.

Thank you


Top
 Profile  
 
 Post subject: Re: I dont want to get the addresses
PostPosted: Wed May 28, 2008 3:49 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
avimar wrote:
As i show the relation is eager, but in the query i want to override the mapping and get users without address.

Thank you


My mistake. Hmm, I am wondering if this can be solved with lazy property setting. You will need to instrument your entity classes though.



Farzad-


Top
 Profile  
 
 Post subject: Look on the following blog
PostPosted: Wed May 28, 2008 4:01 pm 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
http://blogs.jboss.com/blog/acoliver/2006/01/23/Hibernate_EJB3_Tuning.txt

in the fetch strategies section he wrote:
Quote:
In H3 when you run an HQL query the mapping file's fetch strategy is ignored for each association and they are loaded lazily by default


No need to instrument.
The ralation on the class should be what ever you want and it should be applied to findById and not to query.

Thank you


Top
 Profile  
 
 Post subject: Re: Look on the following blog
PostPosted: Wed May 28, 2008 4:04 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
avimar wrote:
No need to instrument.
The ralation on the class should be what ever you want and it should be applied to findById and not to query.



Sure, but the only thing I don't know is how it reacts when it comes to a one to one relationship. The problem here is that one to one implies coexistence of the entities and this might be ignored for a one to one relationship. Let me know if you could get it to work.


Farzad-


Top
 Profile  
 
 Post subject: Sorry
PostPosted: Wed May 28, 2008 4:10 pm 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
I still don't understand why to instrument.
Instrumented need if you want "columns" to be lazy fetched.

here i have OneToOne with JoinColumn , you can add fetch attribute to the OneToOne, but...

i want when i run findById the address need to also be loaded
if i run query only and only the entities , which explicitly define in the query need to be loaded.
look on the blog i sent.

Thank you


Top
 Profile  
 
 Post subject: It also happen in onetomany
PostPosted: Wed May 28, 2008 5:40 pm 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
what do you undesrtand from the following?
http://www.hibernate.org/315.html

Do you understand it override?


Top
 Profile  
 
 Post subject: I did the following test
PostPosted: Thu May 29, 2008 9:41 am 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
Code:
   @OneToOne(cascade = { CascadeType.ALL})
   @JoinColumn
   @Fetch(FetchMode.JOIN)
   @LazyToOne(LazyToOneOption.PROXY)
   public Address address = new Address();


And HQL - select userE from UserEntity as userE

Still there is select for each adress.


Top
 Profile  
 
 Post subject: Re: I did the following test
PostPosted: Thu May 29, 2008 11:29 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I am wondering what happens if you change this to a many-to-one eager relationship?



Farzad-


Top
 Profile  
 
 Post subject: No still execute select for each address
PostPosted: Thu May 29, 2008 2:49 pm 
Beginner
Beginner

Joined: Mon Apr 07, 2008 12:49 pm
Posts: 33
It is very disapointing to discover that you can override the eager of the onetoone.


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