EJB Glassfish v3.1.2客户端将数据传递给会话bean始终为空 [英] EJB Glassfish v3.1.2 client passed data to session bean is always null

查看:210
本文介绍了EJB Glassfish v3.1.2客户端将数据传递给会话bean始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在客户端调用session bean方法传递方法参数$ p
$ b

应用程序时,我遇到问题,数据到达方法调用始终为空或设置为默认值。



,而该方法的过程与对象



有效,例如:



- 我们有方法来持久化一个对象实体addStudent(Student student);
- 从客户端我们创建学生对象设置学生字段,如学生姓名等,调用addStudent(weStudent)方法;
这个我们的学生达到了null或默认值的字段的方法。该学生将添加
这些空字段。



提前感谢。

解决方案

您正在使用EclipseLink进行编织,它不起作用。你应该尝试不编织。
可能通过编辑您的 persistence.xml

 < persistence-unit name =XXXtransaction-type =XXX> 
< jta-data-source> XXX< / jta-data-source>
< jar-file>或类别列表或其他< / jar-file>
<属性>
[其他属性]
< property name =eclipselink.weavingvalue =false/>
< / properties>
< / persistence-unit>

更新:
JPA实现可以处理实体有几种替代方法,这是一种无穷尽的列表:




  • 扩展(这是JPA规范要求无私有默认
    实体的方式)

  • 包装

  • 类的字节代码操作(使其符合EclipseLink想要的方式)

  • <使用属性
  • 使用getter setter(如果有的话)的基本反射



EclipseLink调用字节代码注入Weaving(什么是Java字节码注入?
动态编织是在运行时进行编织 - 基本上当类由加载器加载时。
静态编织在部署前进行编织,但在编译之后。
对于EclipseLink编织是性能最快的方法,它也是其他原因的首选方法。不幸的是,编织工作往往有点棘手。对于您的项目来说,这是完全可能的,对于很多典型的项目来说,这并不重要。



如果有客户端通过远程接口访问bean,并且存在作为参数传递的实体或通过该连接返回值动态编织将不起作用。
在大多数生产场景中,特别是如果应用程序/产品不是非常小的静态编织优先于动态编织...
要了解有关静态和动态编织的更多信息以及如何配置我避风港真的找不到任何优秀的来源,但这至少是半官方的:
Using_EclipseLink_JPA_Weaving



发生了什么事情是实体被编织在一端,而不是编织在另一端 - >绝对不能工作。 p>

好消息是,您可能根本无需关心任何这种编织的东西,或者您可能。
当您禁用编织时,EclipseLink回到了处理JPA实体的另一种方法。
EclipseLink只有启用了编织才有支持的功能(不需要JPA)。



From: What_You_May_Need_to_Know_About_Weaving_JPA_Entities
列出EclipseLink明确使用织造的东西:




  • 懒惰加载(间接)

  • 更改跟踪

  • 抓取组

  • 内部优化



(对于其中一些,如果编织被禁用,则会有其他方法的后备,我猜所有但是内部优化)


I am having a problem when calling session bean method passing method parameters from client

application, the data reaches the method call is always null or set to default value.

while the process of the method works well with the object

for example:

-we have method to persist an object entity addStudent(Student student); - from the client we create the student object setting student fields like student name and so on, calling the method addStudent(ourStudent); this ourStudent reaches method with fields of null or default value. the student is added with these empty fields.

Thanks in advance.

解决方案

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")

这篇关于EJB Glassfish v3.1.2客户端将数据传递给会话bean始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆