简体   繁体   English

在服务器端调用业务方法返回被管实体时客户端出错

[英]Error on client side while calling a business method on server side returning managed entity

My client application is a standalone java application using Netbeans RCP. 我的客户端应用程序是使用Netbeans RCP的独立Java应用程序。 The client application connect to a remote EJB mounted on a Glassfish server. 客户端应用程序连接到Glassfish服务器上安装的远程EJB。

On the server side, i have a business method (i made for testing) that's supposed to take an instance of an entity (this entity is not persisted or managed yet), persist it (using the persit of the EntityManager ). 在服务器端,我有一个业务方法(我用于测试),它应该接受一个实体的实例(该实体尚未持久化或管理),持久化它(使用EntityManagerpersit )。

Here is how this method looks like: 以下是此方法的外观:

@Override
public TestLinkEntity test(TestLinkEntity c) {
    em.persist(c);
    return c;
}

Called from the client side like this: 从客户端调用如下:

TestLinkEntity c = remote.test(new TestLinkEntity());

Here is the TestLinkEntity declaration: 这是TestLinkEntity声明:

@Entity
public class TestLinkEntity implements AltEntity, Serializable {

    private Set<TestAppEntity> links = new HashSet<TestAppEntity>();

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @OneToMany(mappedBy="links")
    public Set<TestAppEntity> getLinks() {
        return links;
    }

}

And now the TestAppEntity used in the one to many relationship. 现在TestAppEntity用于一对多的关系。

@Entity
public class TestAppEntity implements Serializable, AltEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String test;

    public TestAppEntity() {
    }

    @Override
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}

The problem i'm facing is when i try to call the business method from the client (as shown above) i get a huge and quite unreadable exception on client side and only on client side. 我面临的问题是,当我尝试从客户端调用业务方法时(如上所示),我在客户端获得了一个巨大且非常难以理解的异常,并且在客户端。 No exception logged on the Glassfish logs and the entity ( TestLinkEntity )and potential links ( TestAppEntity ) are stored in the data base. Glassfish日志上没有记录异常,实体( TestLinkEntity )和潜在链接( TestAppEntity )存储在数据库中。

I pasted the exception here . 我在这里粘贴了这个例外。

Here are few things i have noticed. 以下是我注意到的一些事情。

  • The exception only happen when i try to return a managed entity. 只有在我尝试返回托管实体时才会发生异常。 If i replace the em.persist() by em.merge and do not return the new entity returned by merge for example, the exception will never be raised. 如果我更换em.persist()em.merge ,不返回由合并例如返回新的实体,该异常将永远不会提高。 eg do something like: 例如,做一些事情:

     @Override public TestLinkEntity test(TestLinkEntity c) { em.merge(c); return c; } 
  • The exception only happen when the entity returned contains the one to many relationship. 仅当返回的实体包含一对多关系时才会发生异常。 eg something like the following code snippet will not raise an exception: 例如,以下代码片段之类的内容不会引发异常:

     @Override public TestAppEntity test(TestAppEntity c) { em.persist(c); return c; } 

    TestAppEntity does not contain any relationship. TestAppEntity不包含任何关系。

Things i'm sure: 我确定的事情:

  • TestAppEntity and TestLinkEntity are the same on both client and server sides. 客户端和服务器端的TestAppEntityTestLinkEntity都是相同的。

EDIT: 编辑:

Due to the answer of @James, i'm now wondering what is the difference between the package javax.persistence in eclispelink.jar and in javaee.jar. 由于@James的答案,我现在想知道eclispelink.jar中的包javax.persistence和javaee.jar之间的区别是什么。 Should i include both? 我应该包括两者吗?

Including both cause troubles (maybe due to the fact that package name in both jars are the same). 包括两者都会引起麻烦(可能是由于两个罐子中的包装名称相同)。

error: in class file javax/persistence/NamedQuery.class(javax/persistence:NamedQuery.class): unknown enum constant     javax.persistence.LockModeType.NONE
Note: Attempting to workaround javac bug #6512707
warning: No processor claimed any of these annotations: [javax.ejb.Remote]
error: in class file j javax/persistence/NamedQuery.class(javax/persistence:NamedQuery.class): unknown enum constant javax.persistence.LockModeType.NONE

It seems to be some bug in the CORBA serialization you are using. 它似乎是您正在使用的CORBA序列化中的一些错误。

My guess is you don't have the eclipseLink.jar on your client, but you need it. 我的猜测是你的客户端上没有eclipseLink.jar,但你需要它。 As objects read from the database will contains special LAZY collections instances. 从数据库中读取的对象将包含特殊的LAZY集合实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM