Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Lazy relationship is intiated, when it shouldn't be
Lazy relationship is intiated, when it shouldn't be [message #514862] Tue, 16 February 2010 22:52 Go to next message
Michal Ondrovic is currently offline Michal OndrovicFriend
Messages: 7
Registered: February 2010
Junior Member
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 22:53]

Report message to a moderator

Re: Lazy relationship is intiated, when it shouldn't be [message #515026 is a reply to message #514862] Wed, 17 February 2010 14:15 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1304
Registered: July 2009
Senior Member

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,
Previous Topic:maven static weaving plugin
Next Topic:[SOLVED] Problem in custom classloader-environment: Object XYZ is not a known entity type
Goto Forum:

Current Time: Wed Oct 17 11:41:11 GMT 2018

Powered by FUDForum. Page generated in 0.02516 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top