wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes annotation for lazy loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "annotation for lazy loading " Watch "annotation for lazy loading " New topic
Author

annotation for lazy loading

srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
I want to use the lazy loading feature from byte code instrumentation. Please tell me how I can make ManyOneTo association lazy what annotation should I use to enable lazy fetching




I tought this would make it lazy but it does not please , tell me what additional annotation should I use to load the entity lazy ?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

How do you know it's not lazy? One to Many relations are lazy by default.

What type of test are you doing? Perhaps you just have an open Hibernate Session?

-Cameron McKenzie
srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
Cameron Wallace McKenzie wrote:How do you know it's not lazy? One to Many relations are lazy by default.

What type of test are you doing? Perhaps you just have an open Hibernate Session?

-Cameron McKenzie


by looking at the query hibernate generated for loading this entity.the query has join to this association , I know I can make it lazy bu telling option=false , but if this is not the case I have to use byte code intrumentation and I did that , but what i did not get is additional hibernate specific annotation to make this lazy ,
By the way onetoMany is not lazy bu default , you can make it lazy only by specifying optional=false
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

You have the ability to either eagerly or lazily fetch associated entities. The fetch parameter can be set to FetchType.LAZY or FetchType.EAGER. EAGER will try to use an outer join select to retrieve the associated object, while LAZY will only trigger a select when the associated object is accessed for the first time. @OneToMany and @ManyToMany associations are defaulted to LAZY and @OneToOne and @ManyToOne are defaulted to EAGER. For more information about static fetching, check Section 2.4.5.1, “Lazy options and fetching modes”.


JBoss Hibernate Documentation Stating @OneToMany Default to Lazy

-Cameron McKenzie
srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
Cameron Wallace McKenzie wrote:
You have the ability to either eagerly or lazily fetch associated entities. The fetch parameter can be set to FetchType.LAZY or FetchType.EAGER. EAGER will try to use an outer join select to retrieve the associated object, while LAZY will only trigger a select when the associated object is accessed for the first time. @OneToMany and @ManyToMany associations are defaulted to LAZY and @OneToOne and @ManyToOne are defaulted to EAGER. For more information about static fetching, check Section 2.4.5.1, “Lazy options and fetching modes”.


JBoss Hibernate Documentation Stating @OneToMany Default to Lazy

-Cameron McKenzie


Yes I wrote it wrong if you look at my code it is @ManyToOne , I want to make @ManyToOne lazy by default it is eager so in order to do that I have to use either byte code instrumentation or say optional=false , I cannot say optional=false and want to use lazy loading from byte code instrumentation , so what annotation should I add to this mapping to make it lazy ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: annotation for lazy loading
 
Similar Threads
Dout in @JoinColumn annotation
Loading the Bean in two different ways
help me with mapping
regarding annotation
collection mapping using set and retain order how to ?