-->
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.  [ 5 posts ] 
Author Message
 Post subject: FetchMode Lazy where the reference is a non-primay unique ke
PostPosted: Mon Apr 14, 2008 2:54 pm 
Newbie

Joined: Sat Dec 30, 2006 3:07 pm
Posts: 16
I have an object A that refers to an object B, by a non-primary unique key.

I want the fetch mode to be lazy, but it appears that this object is always retrieved using a subselect.

If not, can I do it with a join?

Thanks

Kal

using annotations 3.3.0, core 3.2.6 and mysql




It appears that in the Loader, line 1860, there is this code

in loadEntity, where proxy is false

result = doQueryAndInitializeNonLazyCollections(
session,
new QueryParameters(
new Type[] { identifierType },
new Object[] { id },
optionalObject,
optionalEntityName,
optionalIdentifier
),
false
);

This object is not a collection, it is a single entity, and it is referenced by a unique non-primary key.

Dont know if that helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 5:27 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
Subselect? As in

Code:
select x,y,z, (select * from X where X.x = A.x)
from A


?

Is your association optional (=nullable)? Hibernate can not proxy a nullable ToOne-association.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 12:11 pm 
Newbie

Joined: Sat Dec 30, 2006 3:07 pm
Posts: 16
sorry no I mistyped.

It fetches the object later, after the original object is loaded, but before the call returns to my code.

Yes it is nullable, ok that makes sense, but when I have fetch=Eager, it does not join, it fetches after the object is constructed, but before my code gets it.

Is there a reason that it is not joining it when I have fetch=Eager?

thanks

Kal


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 12:24 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
You mean the attribute fetchType in your @(Many|One)ToOne annotation or the @Fetch annotation?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 15, 2008 1:45 pm 
Newbie

Joined: Sat Dec 30, 2006 3:07 pm
Posts: 16
I added fetch

I have

public class T {
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="a", referencedColumnName="id")
private A a;
}

public class A {

@Fetch(FetchMode.JOIN)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "b", referencedColumnName="b")
private B b;

@Fetch(FetchMode.JOIN)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "c")
private C c;
}


public Map<Integer, T> getT(Criteria crit) {
Map<Integer, T> list = new HashMap<Integer, T>();

ScrollableResults scroll = getScroll(crit);
scroll.beforeFirst();
while (scroll.next()) {
T t = (T) scroll.get(0);
list.put(t,getId(), track);
}
return tracks;
}


On scroll.next(), I get a hibernate query in my logs, if t.a.b or t.a.c are not null


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