Lazy relationship is intiated, when it shouldn't be [message #514862] |
Tue, 16 February 2010 17:52  |
Eclipse User |
|
|
|
Dear all,
I have a problem with eclipselink 2.0. I have two entities A and B. A has onetomany relation to B and B has manytoone relation to A. Both relationships are lazy. I'm loading the B entity from server's session bean. In this session bean I'm calling entitymanager.find() or entitymanager.createNamedQuery("B.findById") (same result).
Everything works until I add a new B entity to A. After saving is this B entity returned containing the A entity(in lazy relationship). Other B entities related to the A entity, are returned correctly. I can see it in my swing client, when I'm clicking in the list - for old B entites is it fast, for the new one is it much slower. Updating an B entity doesn't cause such behaviour. I tried to play with cascade in onetomany, but this doesn't help me.
The only solution, that I've found is to call entitymanager.clear() after merge A entity (and flush), but I don't think it's good...
When updating A, I set the relation to A in the new B entites, because without this are the new Bs unrelated (in database have null FK).
Can anybody help me?
Thank you
[Updated on: Tue, 16 February 2010 17:53] by Moderator
|
|
|
Re: Lazy relationship is intiated, when it shouldn't be [message #515026 is a reply to message #514862] |
Wed, 17 February 2010 09:15  |
Eclipse User |
|
|
|
Hello,
I'm not quite sure I understood what you meant in the description of the problem - what exactly is slow? Is it accessing the A from the new B?
Lazy relationships are only untriggered when the object is first loaded from the database. Once they get triggered, the relationships are loaded and remain loaded until the entity is refreshed/reloaded from the database. Could this be what you are seeing? The act of adding a new B to A's collection of Bs will generally cause it to initialize the collection.
Best Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.03490 seconds