Call remote EJB in EJB 3.1

I need to call Remote aneless EJB from another web application using the same glass fish (final version 3.1) that returns an Entity Bean (JPA 2 / Eclipselink). I get an ejb link in a web application via Injection Dependancy (@EJB), but the object becomes null.I google and found that this could be a Serializable problem. Somewhere I found it

TopLink either modifies object classes ("weaves" them) onto the load or substitutes access to the collection at runtime capable of detecting lazy access or altered relationships (there is no way to support lazy loading without this or subclassing or using a proxy at runtime). This brings us to a very important point: you should not use to access the object, but only through your business methods. the bound object is serialized to the server and deserialized on a client that does not have the corresponding entity woven, serialVersionUIDs will not match the calculation. The value includes the fields of the classes and Methods.

So, I need a DTO conversion in my application ???

+4
source share
3 answers

What do you mean by but entity? Are you calling a method on the remote SessionBean and returning zero, or returning, and Entity, whose connection is null?

If this is a null relationship, it could be a LAZY problem, if your relationship is LAZY, and were not received or available, then it will be null. You need to either get it, access it, or make it EAGER.

If you return zero, then something else is wrong.

+2
source

You may be affected by Error in Glassfish 16164 .

A suggested workaround is to add this property to persistence.xml:

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

This solved the problem in my case.

+2
source

Remote EJB with EclipseLink and Glassfish does not work when you try to return an object.

Same for Hibernate, you need to delete the whole proxy server before returning the response. With Hibernate, you need to clear and clear the persistence context before deleting the proxy. If not loaded, set the attribute to null. You can make it work with Java EE interceptor.

But EclipseLink does not work like Hibernate. Even if you clear the persistence context, get / set on the lazy attribute will try to extract. Even out of the deal.

If you set the property name = "eclipselink.weaving" value = "false", this will work because EclipseLink will not change the bytecode of your POJO class, but ManyToOne will always be extracted. In this way, it can load the database into memory.

The only way to resolve this is to use DTO or use Hibernate with an interceptor.

EDIT: You can always override serialization of an entity using the Externalization interface. Get the object in the field to make sure that lazy selection is not applied.

Openjpa also apparently uses the weaving method. http://openjpa.apache.org/entity-enhancement.html

0
source

Source: https://habr.com/ru/post/1346652/


All Articles