Difference between static and dynamic weaving [message #1734638] |
Fri, 10 June 2016 03:03  |
Eclipse User |
|
|
|
I use eclipselink 2.6.3 and have the following code:
public Temp getTemp() {
EntityManager em=emf.createEntityManager();
String queryString="SELECT a FROM Temp a";
EntityGraph<Temp> eg = em.createEntityGraph(Temp.class);
eg.addAttributeNodes("id");
//eg.addAttributeNodes("name");
Query query = em.createQuery(queryString);
query.setHint("javax.persistence.fetchgraph", eg);
List<Temp> items=query.getResultList();
em.close();// ENTITYMANAGER IS CLOSED
return items.get(0);
}
public void temp(){
Temp temp=getTemp();
System.out.println("id:"+temp.getId());
System.out.println("name:"+temp.getName());
}
Situation 1:
When weaving is static (<property name="eclipselink.weaving" value="static"/> + de.empulse.eclipselink weaving plugin) and we do temp.getName() onemore SQL query is executed and necessary data is loaded. In spite of the fact we did close entity manager. I expected to get exception at temp.getName().
Situation 2:
However, when weaving is dynamic (<property name="eclipselink.weaving" value="true"/>) I get exception:
java.lang.ClassNotFoundException: org.eclipse.persistence.internal.jpa.EntityManagerImpl not found by com.temp [57]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.temp.Temp._persistence_checkFetched(Temp2.java)
at com.temp.Temp._persistence_get_name(Temp2.java)
at com.temp.Temp.getName(Temp.java:44)
How to explain this difference? Is this a bug?
[Updated on: Fri, 10 June 2016 03:10] by Moderator
|
|
|
|
Re: Difference between static and dynamic weaving [message #1734883 is a reply to message #1734638] |
Mon, 13 June 2016 09:37  |
Eclipse User |
|
|
|
Your question title doesn't match what you are asking/showing in your post. Your title's question should be answered by http://www.eclipse.org/eclipselink/documentation/2.5/concepts/app_dev007.htm as dynamic and static weaving are both just ways to change the bytes of your java class to allow EclipseLink to put in some performance enhancements it can then use at runtime - such as lazy 1:1 relationships.
Situation 1 does not give you an exception, as EclipseLink has always given you the data requested as long as the context is still available. Just closing an EM doesn't close out the Factory and the resources that can be used to fetch the data, so EclipseLink just does it for you. You can force an exception by serializing your entity, since then the context isn't available, or by handling it in your application methods, but most people find the lack of an exception beneficial.
Situation 2 means you have an issue with your classloading setup correctly, so that the class's classloader cannot find EclipseLink's classes. I don't know why this would be different in dynamic or static weaving, so I suspect that you never really ran the static weaver on your jars or they might get this problem too.
|
|
|
Re: Difference between static and dynamic weaving [message #1734890 is a reply to message #1734638] |
Mon, 13 June 2016 09:37  |
Eclipse User |
|
|
|
Your question title doesn't match what you are asking/showing in your post. Your title's question should be answered by http://www.eclipse.org/eclipselink/documentation/2.5/concepts/app_dev007.htm as dynamic and static weaving are both just ways to change the bytes of your java class to allow EclipseLink to put in some performance enhancements it can then use at runtime - such as lazy 1:1 relationships.
Situation 1 does not give you an exception, as EclipseLink has always given you the data requested as long as the context is still available. Just closing an EM doesn't close out the Factory and the resources that can be used to fetch the data, so EclipseLink just does it for you. You can force an exception by serializing your entity, since then the context isn't available, or by handling it in your application methods, but most people find the lack of an exception beneficial.
Situation 2 means you have an issue with your classloading setup correctly, so that the class's classloader cannot find EclipseLink's classes. I don't know why this would be different in dynamic or static weaving, so I suspect that you never really ran the static weaver on your jars or they might get this problem too.
|
|
|
Powered by
FUDForum. Page generated in 0.09601 seconds