• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hiberate: Help with lazy initialization

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I want to enforce lazy initialization of a relational object.

My structure is:
Every table has a modifiedBy column. The modifiedBy column reference a foreign key to the user table. My beans have the exact structure.

What I want to do is prevent the modifiedBy (user object) from being initialized every time I retrieve an object.

Here is a segment from my mapping file:


Every time I retrieve an address object, a select statement is executed...I don't want that.
I tried to set lazy="no-proxy", but still doesn't help.

Any help is appreciated.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add to the dilemma, here is another confusing outcome.

If I retrieved a list of addresses, the User object (modifiedBy) is not loaded with each object, but if I retrieved a single address object, the User object (modifiedBy) is always loaded.

Any ideas?!
 
Francois Nadeau
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hanna,

Have you tried setting lazy to "true"?



Cheers,
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Francois Nadeau wrote:Hi Hanna,

Have you tried setting lazy to "true"?



Cheers,


For many-to-one the accepted values for lazy="proxy|no-proxy|false". True is not an option.

Thanks
 
Francois Nadeau
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of Hibernate are you using? I googled around a little for your problem, and it seems that some versions have a bug preventing lazy fetching.

http://opensource.atlassian.com/projects/hibernate/browse/HHH-1435

I must confess that I have not used hbm files for a number of years, but I have mapped lazy many-to-one relationships with annotations, and I know that it works with my current project which uses version 3.0.0.GA:



Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic