-->
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.  [ 7 posts ] 
Author Message
 Post subject: No Lazy loading with many-to-one when not-found="ignore
PostPosted: Thu Feb 01, 2007 10:12 am 
Newbie

Joined: Wed Jan 31, 2007 4:18 pm
Posts: 1
Hello,

I am facing a weird problem with Hibernate.3.2.2.ga
when my mapping file is using a many-to-one relation =>

<hibernate-mapping>
<class name="Currencies" table="Currencies">
<id column="Currencies_Id" name="currenciesId">
<generator class="native"/>
</id>
<many-to-one class="Cities" column="Cities_Id" name="citiesRef"/>
</class>
</hibernate-mapping>

with the previous mapping , I am having lazy loading, only one select to get the Currencies
when I am adding not-found="ignore" to the mapping file

<many-to-one class="com.reuters.webaccess.vo.gen.Cities" column="Cities_Id" name="citiesRef" not-found="ignore"/>

no more lazy loading with the previous mapping file, 2 selects:
one for the Currencies, one for the Cities.

What is the link between lazy loading and the not-found attribute ?

Thank you for your help!!


Top
 Profile  
 
 Post subject: I'm experiencing the same issue...
PostPosted: Wed Feb 28, 2007 11:57 am 
Newbie

Joined: Thu Feb 10, 2005 10:52 am
Posts: 5
A quick bump, because I'd love to see an answer on this from anyone in the know. We're experiencing the same issue.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 28, 2007 9:01 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
When not-found="ignore" is specified, a missing row is treated as a null association. Since many-to-one uses a proxy to load, lazy loading will create issues if the row is not found, since an unassociated proxy will have got created. Eager fetch is therefore the solution.

Having said that, what is the issue that you are facing? We can then suggest a solution which might help you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 28, 2007 9:44 pm 
Newbie

Joined: Thu Feb 10, 2005 10:52 am
Posts: 5
One of our primary business entities may optionally have a many-to-one association to a "folder" in a virtual/database-based file manager. This many-to-one association's lazy loading works perfectly well when not-found="ignore" is not specified.

However, when it is specified, Hibernate fetches the folder entity for the reason you explained previously. For some reason, fetching the folder entity causes a good chunk of the subordinate graph to be loaded. If the folder entity is fetched by ID directly, the subordinate graph is not loaded. If not-found="ignore" is not specified, none of the graph is loaded.

I've been using Hibernate for two years now, and I feel confident the mapping files are correct as they work perfectly in all other instances. As you can imagine, a virtual file system can have infinite layers in much the same way as an NTFS or FAT file system. Hence, lazy the lazy initialization ability of Hibernate is a great asset here.

Could you elaborate more on how fetch="eager" could assist in this scenario, or point me to an online document? It might be the workaround I'm looking for, as I'd like to keep the not-found exceptions suppressed while maintaining my lazy initialization strategy.

Thanks!

- James Chrystal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 28, 2007 10:06 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Try lazy="no-proxy" in the many to one definition along with not-found="ignore".


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 28, 2007 10:27 pm 
Newbie

Joined: Thu Feb 10, 2005 10:52 am
Posts: 5
Will do - I'll post back my findings tomorrow when I test it (Friday if we get snowed in!).

Thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 7:36 pm 
Newbie

Joined: Thu Apr 19, 2007 11:47 pm
Posts: 2
Just to register: i did and it was ok.

Code:
@ManyToOne
@JoinColumns( {
   @JoinColumn(name="NUM_PROTOCOLO", referencedColumnName="NUM_PROTOCOLO"),
   @JoinColumn(name="ANO_PROTOCOLO", referencedColumnName="ANO_PROTOCOLO")
   } )
@LazyToOne(value=LazyToOneOption.NO_PROXY)
@org.hibernate.annotations.NotFound(action=NotFoundAction.IGNORE)


DonĀ“t forget the instrumentation.


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