-->
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.  [ 3 posts ] 
Author Message
 Post subject: Custom constructor and JOIN FETCH problem
PostPosted: Wed Jun 16, 2010 9:11 am 
Newbie

Joined: Wed Jun 16, 2010 8:52 am
Posts: 1
Hi everyone.

I've been having some problems with Lazy loading of non-collection associations, using a non-default constructor.

Looking at this example:
Code:
select new Message(m.id, action)
from Message as m
    join m.action as action


If we assume the action property as being an entity of the type Action, and also assuming that on the Message we have it defined like this:
Code:
class Message {
...
@ManyToOne(targetEntity = Action.class, fetch = FetchType.LAZY)
@JoinColumn(name = "ACTION_ID", referencedColumnName = "ACTION_ID", nullable = false)
private Action action;
...
}


so with this scenario, if i run the first query, i will get LazyInitializationException, since the mate Object received by the Message constructor wasn't "fetch", thus i tried to change the query to:

Code:
select new Message(m.id, action)
from Message as m
    join fetch m.action as action


but then i get this:
QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list

Any ideas on how to work around this issue, other than doing it like this:
Code:
select new Message(m.id, action.field1, action.field2, action.field3 ... )
from Message as m
    join fetch m.action as action

and then having a Message constructor receiving all the fields from the Action that i need to create an Action object and assign it to the Message's action field manually ?

Thanks in advance.
<3


Top
 Profile  
 
 Post subject: Re: Custom constructor and JOIN FETCH problem
PostPosted: Thu Jun 17, 2010 7:24 am 
Newbie

Joined: Thu Jun 17, 2010 7:22 am
Posts: 1
I have the same problem...


Top
 Profile  
 
 Post subject: Re: Custom constructor and JOIN FETCH problem
PostPosted: Mon Jul 05, 2010 1:56 pm 
Newbie

Joined: Mon May 31, 2010 7:29 am
Posts: 5
Me too. In some other posts Hibernate Team say that it does not make sense to use join fetch with a constructor, but in some cases if it´s not used i got lazy problem...


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