Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home »  » EclipseLink » SQL generated even for FetchType.LAZY reference(unnecessary DB calls)
SQL generated even for FetchType.LAZY reference [message #1737561] Sun, 10 July 2016 01:52 Go to next message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 12
Registered: July 2016
Junior Member
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 16:00 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1275
Registered: July 2009
Senior Member
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 17:11 Go to previous messageGo to next message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 12
Registered: July 2016
Junior Member
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 20:47 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1275
Registered: July 2009
Senior Member
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 23:32 Go to previous message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 12
Registered: July 2016
Junior Member
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 23:35]

Report message to a moderator

Previous Topic:QUERY_RESULTS_CACHE vs CACHE_USAGE and QUERY_TYPE
Next Topic:Access raw unmapped data from Entity
Goto Forum:
  


Current Time: Sun Dec 17 00:30:25 GMT 2017

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

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