Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

annotation for lazy loading

 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic