EclipseLink deserializes an empty entity object on remote EJB call

﹥>﹥吖頭↗ 提交于 2019-12-08 04:14:20

问题


I am using the current release of GlassFish 4.1 with EclipseLink version 2.5.2 included. At this GlassFish, I have an enterprise application and a web application deployed. If an EJB that returns a loaded entity, is called from outside the GlassFish (like an external JavaFX application), the entity is returned properly.

But if the same EJB is called from the web application, the entity is not returned properly due to this bug GLASSFISH-17432.

The workaround I already found here Calling Remote EJB in EJB 3.1 is not really solving this problem, because if I disable the weaving in EclipseLink, the following does not work any more properly:

@ManyToOne(fetch=FetchType.LAZY)
public Foo getFoo() {
    return foo;
}

@ManyToOne(fetch=FetchType.EAGER)
public Bar getBar() {
    return bar;
}

回答1:


You can try static weaving as another workaround.

Byte code weaving is a technique for changing the byte code of compiled Java classes. You can configure byte code weaving to enable a number of EclipseLink JPA performance optimizations, including support for the lazy loading of one-to-one and many-to-one relationships, attribute-level change tracking, and fetch groups.

Weaving can be performed either dynamically when entity classes are loaded, or statically as part of the build process.

(Source)

As suggested in GLASSFISH-16164 you can try the eclipselink-staticweave-maven-plugin. A detailed explanation about static weaving and the usage of the plugin (alternativly you can use ant) can be found in the EclipseLink Wiki.

You then have to set this property in your persistence.xml:

<property name="eclipselink.weaving" value="static"/>

See also:

  • How to enable weaving in EclipseLink?
  • Java-EE6: FetchType.LAZY with static weaving throws strange exception
  • Lazy loading does not works for ManyToOne in eclipselink
  • Why doesn't JPA's FetchType.LAZY work?


来源:https://stackoverflow.com/questions/27741319/eclipselink-deserializes-an-empty-entity-object-on-remote-ejb-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!