问题
My client application is a standalone java application using Netbeans RCP. The client application connect to a remote EJB mounted on a Glassfish server.
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
).
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:
@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.
@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.
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()
byem.merge
and do not return the new entity returned by merge for example, the exception will never be raised. e.g 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. e.g 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.
Things i'm sure:
TestAppEntity
andTestLinkEntity
are the same on both client and server sides.
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. 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
回答1:
It seems to be some bug in the CORBA serialization you are using.
My guess is you don't have the eclipseLink.jar on your client, but you need it. As objects read from the database will contains special LAZY collections instances.
来源:https://stackoverflow.com/questions/13267692/error-on-client-side-while-calling-a-business-method-on-server-side-returning-ma