-
1. Re: Jboss 7.1 eclipselink and lazy loading
rcd May 30, 2012 1:44 PM (in response to syd108)EclipseLink lazy loading works for me in AS7; see here for my setup. My first suggestion would be to try updating to a nightly or milestone build of EclipseLink 2.3.3 or 2.4.0. EclipseLink 2.3.2 and earlier have some known issues regarding JBoss integration that are fixed in these builds.
-
2. Re: Jboss 7.1 eclipselink and lazy loading
syd108 May 31, 2012 12:58 PM (in response to rcd)Rich: Thank you for the response. I will try with a milestone release of Eclipselink and will post results.
-
3. Re: Jboss 7.1 eclipselink and lazy loading
syd108 May 31, 2012 8:37 PM (in response to syd108)Still no luck. Upgraded to the latest eclipselink 2.4.0 Milestone 20 build.
Here is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="IMPS_Core">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/ImpsDatasource</jta-data-source><class>com.beans.Asset</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="JBoss" />
<property name="eclipselink.weaving" value="dynamic" />
<property name="eclipselink.weaving.lazy" value="true"/>
<property name="eclipselink.weaving.fetchgroups" value="false"/>
<property name="eclipselink.weaving.changetracking" value="false"/>
<property name="eclipselink.orm.throw.exceptions" value="true"/>
<property name="eclipselink.target-database" value="Oracle" />
<property name="eclipselink.jdbc.cache-statements" value="true" />
<property name="eclipselink.jdbc.cache-statements.size" value="0" />
<property name="eclipselink.jdbc.native-sql" value="true" />
<property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.exclude-eclipselink-orm" value="false" />
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
<property name="eclipselink.logging.level.sql" value="FINEST" />
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>Eclipselink module starts up (
17:04:56,408 INFO [stdout] (MSC service thread 1-2) [EL Info]: 2012-05-31 17:04:56.407--ServerSession(1745547905)--EclipseLink, version: Eclipse Persistence Services - 2.4.0.v20120528-r11520
) and runs perfect until we try to do lazy loading. We get the following error.
Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that lazy relationship is traversed after serialization. To avoid this issue, instantiate the LAZY relationship prior to serialization.
My module.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Represents the EclipseLink 2.4.x module-->
<module xmlns="urn:jboss:module:1.1" name="org.eclipse.persistence">
<resources>
<resource-root path="eclipselink-2.4.0.jar"/>
</resources>
<dependencies>
<module name="asm.asm"/>
<module name="javax.api"/>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="javax.validation.api"/>
<module name="javax.xml.bind.api"/>
<module name="org.antlr"/>
<module name="org.apache.ant"/>
<module name="org.apache.commons.collections"/>
<module name="org.dom4j"/>
<module name="org.javassist"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>In our Code: when we do
grantList = authority.getCtsGrants();
if grantList.size() > 0) // where grants is a one to many relationship for the authority object.
We get the lazy initialization above error. The only thing I notice in the jboss modules directory for the javax.persistence.api is the hibernate jars. Should I replace them with the persistence jars provided with the eclipselink downloads?
cheers,
Naveen Sydney
-
4. Re: Jboss 7.1 eclipselink and lazy loading
rcd May 31, 2012 9:27 PM (in response to syd108)Thoughts:
- About the javax.persistence.api JARs, I didn't need to replace those to get EclipseLink working, so you shouldn't need to either.
- You've got a lot of EclipseLink properties set in your persistence.xml. I don't, so it's possible one of those is the problem. As documented in my guide, I only have eclipselink.weaving = static, eclipselink.target-server = JBoss, and eclipselink.logging.logger = the custom logging class for which code is provided in my guide.
- You've got dynamic weaving set up. As I said in my guide, I noticed some issues with dynamic weaving. I didn't get it working far enough to test lazy loading with dynamic weaving, so that may be broken right now as well. Try using static weaving instead.
- Do you really only have a single entity class in your persistence.xml? I'm guessing the "authority" and "grant" objects are different classes. As I said in my guide, right now EclipseLink is incapable of discovering entity classes automatically in AS7, so ALL of your entity classes MUST be listed in persistence.xml. I have set <exclude-unlisted-classes>true</excluse-unlisted-classes> in my persistence.xml as a reminder of this fact.
-
5. Re: Jboss 7.1 eclipselink and lazy loading
smarlow May 31, 2012 10:01 PM (in response to syd108)Are you still in the same JTA transaction where the "authority" entity was read or is "authority" perhaps detached from the persistence context?
-
6. Re: Jboss 7.1 eclipselink and lazy loading
syd108 May 31, 2012 10:23 PM (in response to rcd)Rich:
I was lazy and did not list all my ejb in the response. I have about 100 ejb's listed.
I will remove the extra properties and test if lazy loading with dynamic weaving as it did in Jboss 6. If that fails I will try to do static weaving
Scott:
The object is detatached. but given that I am using the local reference as opposed to remote the lazy initializing should work correct?
Thanks for all your help. I will post my progress.
cheers,
Naveen Sydney
-
7. Re: Jboss 7.1 eclipselink and lazy loading
smarlow Jun 1, 2012 8:53 AM (in response to syd108)Naveen,
Before accessing the lazy part, merge the "authority" entity back into the persistence context so that it will be managed. See if that helps.
Scott
-
8. Re: Jboss 7.1 eclipselink and lazy loading
rcd Jun 1, 2012 9:20 AM (in response to smarlow)Scott,
That might help, but, as Naveen said, it shouldn't be necessary. One of the primary advantages EclipseLink has over Hibernate (which was one of the reasons I was motivated to switch) is that lazy relationships can still be accessed even after the EntityManager is closed; i.e. transparent lazy loading and no more LazyInitializationException nonsense. As far as I can tell, lazy loading works fine while detached from the EntityManager in my setup. I would expect to see a problem if there were some remoting going on, but Naveen says he isn't doing that.
Rich
-
9. Re: Jboss 7.1 eclipselink and lazy loading
smarlow Jun 1, 2012 10:05 AM (in response to rcd)Rich,
I didn't know that but It would still be a worthwhile test (as a possible workaround). I'd also like to see TRACE logging output for org.jboss.as.jpa when this problem occurs. This doc explains how to enable TRACE logging for JPA. I think that you (or someone else) previously mentioned that EclipseLink doesn't have TRACE logging.
With EclipseLink (when the lazy loading works from a detached entity), is the lazily loaded part detached as well? I assume yes but would like to know what to expect with their extension.
Scott
-
10. Re: Jboss 7.1 eclipselink and lazy loading
rcd Jun 1, 2012 6:43 PM (in response to smarlow)Scott,
EclipseLink has some low-level logging, but it's not as extensive as Hibernate. On the other hand, I've found EclipseLink's exception messages to be much more detailed and useful than Hibernate's. EclipseLink technically doesn't have TRACE logging because it uses JDK logging levels (unless you're using a custom logger like the one I wrote, which translates the JDK levels to SLF4J levels) but it does have FINE/FINER/FINEST. Setting the level to FINEST results in the typical deluge of log statements.
As for the question about whether the lazy loaded part is detached, I don't know and I'm not able to find out right now. I could possibly look into it sometime next week, but I'm not really sure it matters.
Rich
-
11. Re: Jboss 7.1 eclipselink and lazy loading
syd108 Jun 3, 2012 4:07 PM (in response to rcd)a) I am using Local Reference so no remoting.
b) I tried em.merge(authority) before accessing the grantList. Still get the same error.
I will try removing the extra properties in the persistence.xml before I try and do static weaving. I will keep everyone posted.
cheers,
Naveen
-
12. Re: Jboss 7.1 eclipselink and lazy loading
syd108 Jun 4, 2012 3:55 PM (in response to syd108)Updates:
Removing the extra properties in the persistence.xml did not help.
I am now attempting static weaving.
FYI:
Noticed that they do not have weaveinplaceforjar not working yet.
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-40007] (Eclipse Persistence Services - 2.4.0.v20120528-r11520): org.eclipse.persistence.exceptions.Sta
Exception Description: An exception was thrown while weaving: [Ljava.lang.String;@18145132
Internal Exception: Exception [EclipseLink-40004] (Eclipse Persistence Services - 2.4.0.v20120528-r11520): org.eclipse.persis
aveException
Exception Description: Performing weaving in place for JAR file is not allowed
at org.eclipse.persistence.exceptions.StaticWeaveException.exceptionPerformWeaving(StaticWeaveException.java:138)
at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.main(StaticWeave.java:86)
Caused by: Exception [EclipseLink-40004] (Eclipse Persistence Services - 2.4.0.v20120528-r11520): org.eclipse.persistence.exc
ion
Exception Description: Performing weaving in place for JAR file is not allowed
at org.eclipse.persistence.exceptions.StaticWeaveException.weaveInplaceForJar(StaticWeaveException.java:76)
at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveProcessor.preProcess(StaticWeaveProcessor.java:206)
at org.eclipse.persistence.tools.weaving.jpa.StaticWeaveProcessor.performWeaving(StaticWeaveProcessor.java:173)
at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.start(StaticWeave.java:115)
at org.eclipse.persistence.tools.weaving.jpa.StaticWeave.main(StaticWeave.java:84)Will post updates as usual.
cheers,
Naveen
-
13. Re: Jboss 7.1 eclipselink and lazy loading
smarlow Jun 6, 2012 1:37 PM (in response to syd108)I'm not 100% its related but someone just mentioned to me that JPA ClassFormer support needs more changes. The PersistenceUnitInfo.addTransformer() will not be injected into the classloader returned from the PersistenceUnitInfo.getClassLoader().
A jira will coming shortly for this.
Scott