Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » SQL generated even for FetchType.LAZY reference(unnecessary DB calls)
SQL generated even for FetchType.LAZY reference [message #1737561] Sat, 09 July 2016 21:52 Go to next message
Eclipse UserFriend
I have a reference in an entity to its parent entity, and annotated it:
@ManyToOne(fetch=FetchType.LAZY)

to prevent it from making an unnecessary database call. Still, I'm seeing SQL generated to retrieve the parent entities, even for those that are common and should have been in the level 1 cache. I shouldn't have had to, but I also enabled the shared cache, and this, as expected, had no effect.

I then tried adding the query hint "eclipselink.batch" with a value of "x.task" (referring to the parent). Now there's only a single single SQL statement generated for the parent, which makes sense.

The batch hint is an improvement, but in the first case, at least, we shouldn't be seeing any DB call made for a LAZY reference, correct? Is there something I need to set to prevent this unnecessary call?
Re: SQL generated even for FetchType.LAZY reference [message #1738871 is a reply to message #1737561] Mon, 25 July 2016 12:00 Go to previous messageGo to next message
Eclipse UserFriend
EclipseLink OneToOne and ManyToOne mappings require weaving in order to use lazy fetching as described here http://www.eclipse.org/eclipselink/documentation/2.5/concepts/app_dev007.htm If you are not in a J2EE container, you may need to use static weaving, or add in the EclipseLInk agent to your classpath for dynamic weaving.
Re: SQL generated even for FetchType.LAZY reference [message #1738886 is a reply to message #1738871] Mon, 25 July 2016 13:11 Go to previous messageGo to next message
Eclipse UserFriend
Hi Chris,

Yes, I already do static weaving, but the unnecessary SQL is still being issued.

Thanks,
Ari
Re: SQL generated even for FetchType.LAZY reference [message #1739155 is a reply to message #1738886] Wed, 27 July 2016 16:47 Go to previous messageGo to next message
Eclipse UserFriend
There are many reasons why indirection/lazy relationships might be triggered: toString methods, any sort of access to the attribute internal to your class itself, load and other events are just a few common ways relationships get unintentionally triggered. If you can, try setting up the query to fail such that you can get a stack trace from when it is executed With it, you can then trace exactly where it is coming from and hopefully determine why.

Re: SQL generated even for FetchType.LAZY reference [message #1739403 is a reply to message #1739155] Sun, 31 July 2016 19:32 Go to previous message
Eclipse UserFriend
Thanks, Chris. I deliberately excluded that field from toString(), etc., but I'm seeing the query calls for those parent records being issued at the same time as the main query. In any case, I'll try what you said and get back to you.

Best,
Ari

[Updated on: Sun, 31 July 2016 19:35] by Moderator

Previous Topic:EclipseLInk level 2 caching
Next Topic:merge not updating pk IDs
Goto Forum:
  


Current Time: Wed Jul 23 21:27:41 EDT 2025

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

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

Back to the top