• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set not initialised on lazy loading

 
Sonx Nkuks
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, my first post here ... I look forward to getting positive response.

I have two objects [Basket,Product] ... i use ManyToMany annotation mapping.. My Basket class is as follows ...

The product class has no Mapping reference to basket class (relationship mapping done on Basket only). Here's how i persist Basket and then load it again to see the persistent data..

And lastly, my DAO ...


The following returns null values ...



Oh, i run this with spring context transaction management
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the product relationship is lazy loaded, this will happen (although I can't see the code of manager.getBasket method, but I'm guessing you've not used any special mechanism to load the many-to-many relationship). You can use a fetch join to eagerly load the many-to-many association. You can get an example here...
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to javaranch ...
 
Sonx Nkuks
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:Since the product relationship is lazy loaded, this will happen (although I can't see the code of manager.getBasket method, but I'm guessing you've not used any special mechanism to load the many-to-many relationship). You can use a fetch join to eagerly load the many-to-many association. You can get an example here...


Hi Ankit, thanks for your response. This was a silly mistake i've done. My datasource point to tables with DB insert (i use HQSLDB). So basket had already a record with primary Id of value 0 (not sure why cause i use a sequence and i tell it to start from one .

So findByReference was picking up this record with the 0 id ... Thanks for the Welcoming, i have another Spring MVC specific quest but will start a new thread
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic