File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Set not initialised on lazy loading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Set not initialised on lazy loading" Watch "Set not initialised on lazy loading" New topic
Author

Set not initialised on lazy loading

Sonx Nkuks
Ranch Hand

Joined: Aug 20, 2010
Posts: 47
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

And welcome to javaranch ...
Sonx Nkuks
Ranch Hand

Joined: Aug 20, 2010
Posts: 47
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set not initialised on lazy loading