<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Eager Loading</title><link>https://answers.axonivy.com/questions/2311/eager-loading</link><description>&lt;p&gt;Hello Ivy Team,&lt;/p&gt;
&lt;p&gt;In my project, I had to switch from the default Eager loading to the Lazy loading of the Entity classes.
The reason was that the queries were not optimized.
Now I have the following problem, every time I try to inspect the variables in debug mode, the Designer is throwing errors and it is almost impossible for debugging:&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/Capture_JJL7IfL.JPG"&gt;&lt;/p&gt;
&lt;p&gt;Best Regards,
Yordan Yunchov&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2311/eager-loading" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 21 Dec 2016 15:49:08 -0500</lastBuildDate><item><title>Answer by Flavio Sadeghi</title><link>https://answers.axonivy.com/questions/2311/eager-loading/2314</link><description>&lt;p&gt;&lt;em&gt;[Edit]: The Bug 'Label Job has encountered a problem' is fixed with 6.5. We return null, since the below explanation is still true.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Lazy evaluation of entity beans is not supported with the ivy persistency. &lt;/p&gt;
&lt;p&gt;As described in the documentation, &lt;strong&gt;ivy persistency always works with unmanaged entity beans&lt;/strong&gt;. Lazy loading is only supported with managed entity beans. A beans is managed as long the referenced session (link to the db/transaction) is open - means the entity is managed (i.e. cached) in the session.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How to solve:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Example: Table Company has a 1:n relation to Invoices. &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First question: is the lazy loading required? Do the Company entity need a list of all invoices or can it be replaced/reduced to the @ManyToOne relation on the Invoice entity? &lt;br&gt;To get the list of all invoices of a company a repositoy method has to be implemented, e.g. &lt;code&gt;InvoiceRepository.readAllOfCompany(Company c) : List&amp;lt; Invoices &amp;gt;;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Write own repository method and open/close the session inside this method. As long the session is open, as long the entiries are managed and lazy loading is supported. Always ensure with a try-finally block that the session gets closed. Otherwise, the connection to the database remains open and the allowed number of connections is limited. An example could be find &lt;a href="http://answers.axonivy.com/questions/1102/how-to-use-jpa-entity-manager-instead-of-ivy-entity-manager"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Flavio Sadeghi</dc:creator><pubDate>Wed, 21 Dec 2016 15:49:08 -0500</pubDate><guid>https://answers.axonivy.com/questions/2311/eager-loading/2314</guid></item></channel></rss>