-->
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: ManyToOne lazy fetching on non primary key associations
PostPosted: Mon Oct 16, 2006 1:58 pm 
Beginner
Beginner

Joined: Tue Oct 10, 2006 3:23 am
Posts: 33
Hi,
Because I have a legacy database I was trying to make an associations between 2 classses whithout using the Pk on the linked class, something like that:

Code:
class Foo
...
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="BAR_TYPE_NAME",referencedColumnName="TYPE_NAME",unique=true)
public Bar getBar()

and
Class Bar
...
@Column(name = "TYPE_NAME",unique=true)
public String getTypeName()...



This works however the lazy option has no effect and bar is always fetched in a secondary select.
Is there a way to lazy fetch Bar in this case and to get it cached, given the fact that typeName is unique?


Thanks in advance


Top
 Profile  
 
 Post subject: Re: ManyToOne lazy fetching on non primary key associations
PostPosted: Thu Oct 26, 2006 5:50 pm 
Newbie

Joined: Thu May 25, 2006 12:23 pm
Posts: 3
mooritze wrote:
This works however the lazy option has no effect and bar is always fetched in a secondary select.
Is there a way to lazy fetch Bar in this case and to get it cached, given the fact that typeName is unique?

Thanks in advance


I just noticed exactly the same thing on my data. I didn't realize that it was limited to the non-primary-key associations as you appear to be stating, but you're not alone in the world. If you've found a solution, please post it. I'll look for a solution too because this is a show stopper for me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 9:55 am 
Newbie

Joined: Wed Dec 29, 2004 3:45 am
Posts: 7
Location: Leuven, Belgium
We're encountering the same problem.
Any chance anyone of the Hibernate Team can comment on this? Is this a bug or something that can't be supported?

Erwin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 14, 2007 5:10 pm 
Newbie

Joined: Wed Mar 14, 2007 4:34 pm
Posts: 1
This topic should be named a little bit more correctly:
instead of:
"ManyToOne lazy fetching on non primary key associations"
something like:
"ManyToOne lazy fetching of properties referring to non-@Id properties"
Though the original title is okay. I just wanted to communicate what I found:
I created two tables, free from any primary/foreign key constraints - and lazy fetching still works in the case when referencedColumnName = <property declared as @Id in the Master Entity> (or referencedColumnName is not mentioned in @JoinColumn annotation (by default)), and it doesn't work (we have eager fetching) when referencedColumnName refers to some other (non @Id, though also unique) property of the Master Entity.


Top
 Profile  
 
 Post subject: Re: ManyToOne lazy fetching on non primary key associations
PostPosted: Sun Sep 05, 2010 2:09 pm 
Newbie

Joined: Fri Sep 04, 2009 4:12 pm
Posts: 4
We're still seeing this issue w/ Hibernate Annotations 3.4.0 (Core 3.3.0). Does anyone know if it's been fixed in more recent versions?


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.