0

I am trying to pass a set of JPA entity from the business tier to the presentation tier. All is deployed on the same app server (Glassfish 4). The client is deployed as a .war file, while the Business Tier as an .ear with the ejb reachable trough a Remote interface.

For this I have those very simple methods, with absolutely no logic:

Client

    public List<CompletedDesign> selectCompletedDesigns() {
        try {
            List<CompletedDesign> designs = customerFacade.selectCompletedDesigns();
            return designs;
        } catch (EJBException e) {
            e.printStackTrace();
        }
        return null;
    }

And in the ejb

// EJB
@Override
@RolesAllowed("customer")
public List<CompletedDesign> selectCompletedDesigns() {

    final Principal callerPrincipal = sessionCtx.getCallerPrincipal();

    String name = callerPrincipal.getName();
    Customer customer = dataXchangeBean.getCustomerByID(name);
    List<CompletedDesign> cds = customerBean.selectCompletedDesigns(customer);
    return cds;
}

Final this is a fragment of the JPA Entity.

@Entity
@Table(name = "COMPLETED_DESIGN")
@NamedQueries({......})
public class CompletedDesign implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "ID")
    private String id;
    @Column(name = "DESCRIPTION")
    private String description;
    @Column(name = "NAME")
    private String name;
    @Column(name = "STATUS")
    private DesignStatus status;    
    @JoinColumn(name = "CUSTOMER_FK", referencedColumnName = "ID")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Customer customerFk;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "designFk", fetch = FetchType.LAZY)
    private List<Product> products;

By putting a breakpoint I can see the cds list is correctly retrieved in the EJB side. The very first question would be, why I am getting a Vector instead of a List ? I am using a TypedQuery from the JPS side and that was supposed to correctly cast the object.

enter image description here

However my main concern is this: in the subsequent breakpoint on the client class itself in the presentation layer, it seems that it cannot fully reconstruct the object, the values are all null, and the type is missing. What am I missing here ?

enter image description here

Leonardo
  • 9,607
  • 17
  • 49
  • 89
  • Hate to ask a stupid question, but are you getting an error when you try to access the Entity or is this an IDE issue? – K.Nicholas Mar 20 '16 at 18:33
  • Actually, I am accessing the object from a JSF page, and with `#{completedDesign.description}` I get nothing on video too. No error at all in the console. – Leonardo Mar 20 '16 at 18:44
  • Well, the code you are showing must be from a `ManagedBean` supporting the page since it is a method. I don't understand the `@Override` annotation on the CustomerFacade EJB. Shouldn't it be `@Stateless`? – K.Nicholas Mar 20 '16 at 19:03
  • Yes it is stateless, but it is accessible trough a @Remote interface. The override has been automatically added by the IDE. – Leonardo Mar 20 '16 at 19:26
  • Yea, best I can say is that the Entity is not being fetched from the database for some reason. There is not enough info here to guess further. – K.Nicholas Mar 20 '16 at 19:39

2 Answers2

0

You are using LAZY loading, which means related objects will be loaded when you access them, and not when the primary object is loaded (so that they won't be loaded if you really don't need them). This however, does not work when the primary object is detached from the session. Therefore you must either use EAGER instead of lazy, or just load (access) the collections you need inside the transaction, before passed over the remote interface.

jon martin solaas
  • 459
  • 1
  • 4
  • 14
  • uhm...the problem is not on the related entity, but on fields like id, name etc..that are just properties of the CompletedDesign – Leonardo Mar 20 '16 at 11:17
0

After having spent days trying to make it work, I found this SO post, which brings to the most obvious solution, a bug with Glassfish and EclipseLink !!!

The SO post: EclipseLink deserializes an empty entity object on remote EJB call

The bug: eclipselink.weaving breaks marshalling out of the box

Community
  • 1
  • 1
Leonardo
  • 9,607
  • 17
  • 49
  • 89