EJB Glassfish v3.1.2 client passed data to session bean is always null

对着背影说爱祢 提交于 2019-12-06 02:48:54
esej

You are using EclipseLink with weaving, and it doesn't work. You should try without weaving. Probably by editing your persistence.xml(s)

<persistence-unit name="XXX" transaction-type="XXX">
    <jta-data-source>XXX</jta-data-source>
    <jar-file>Or List of Classes or something else</jar-file>
    <properties>
      [other properties]
      <property name="eclipselink.weaving" value="false"/>
    </properties>
  </persistence-unit>

Update: There are several alternative ways a JPA implementation could handle entities, this is a none exhausting list:

  • Extension (this is way the JPA spec requires a none private default constuctor for entities)
  • Wrapping
  • Byte code manipulation of the class (to make it conform to how EclipseLink "wants" it to be)
  • ThreadLocal proxy thingie
  • Basic reflection using the properties
  • Basic reflection using the getters setters (if there are any)

EclipseLink calls byte code injection "Weaving" ( What is Java bytecode injection? ) Dynamic weaving is doing the weaving at "runtime" - basically when the class is loaded by a class loader. Static weaving is doing the weaving before deployment, but after compilation. For EclipseLink weaving is the fastest method performance wise, it is also the prefered method for other reasons. Unfortuneatly it is often a bit tricky to get weaving to work. It is fully possible none of that matters for your project, it doesn't for a lot of typical projects.

If there are clients that access beans via an remote interface, and there are entities passed as arguments or returns value through that connection dynamic weaving won't work. In most production scenarios, especially if the app/product isn't very small static weaving is prefered over dynamic weaving anyways ... To read more about static vs dynamic weaving and how to configure it I haven't really found any excellent sources, but this one is at least semi official: Using_EclipseLink_JPA_Weaving

What was happening to you was that the entity was weaved at one end and not weaved at the other -> can absolutely not work.

The good news is that you probably don't have to care about any of this weaving thing at all, or you might. When you disabled weaving, EclipseLink fell back to another method for handling the JPA entities. There are some functions EclipseLink only supports if weaving is enabled (none JPA required though).

From: What_You_May_Need_to_Know_About_Weaving_JPA_Entities Comes a list of things that EclipseLink explicitly uses weaving for:

  • lazy loading (indirection)
  • change tracking
  • fetch groups
  • internal optimizations

(For some of them there are fallbacks to other methods if weaving is disabled, I'd guess all but "internal optimizations")

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