JPA实体没有正确地从EJB传递到表示层 [英] JPA entity is not correctly passed from EJB to Presentation Tier

查看:101
本文介绍了JPA实体没有正确地从EJB传递到表示层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一组JPA实体从业务层传递到表示层。全部部署在同一个应用服务器上(Glassfish 4)。客户端部署为.war文件,而Business Tier作为.ear,ejb可通过Remote接口访问。



为此,我使用了非常简单的方法,完全没有逻辑:

客户

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

而在ejb中

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

final Principal callerPrincipal = sessionCtx.getCallerPrincipal();

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

最后这是JPA实体的一个片段。

  @Entity 
@Table(name =COMPLETED_DESIGN)
@NamedQueries({......})
public class CompletedDesign实现Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(可选= false)
@NotNull
@Size(min = 1,max = 20)
@Column(name =ID )
私人字符串ID;
@Column(name =DESCRIPTION)
私有字符串描述;
@Column(name =NAME)
私人字符串名称;
@Column(name =STATUS)
私人DesignStatus状态;
@JoinColumn(name =CUSTOMER_FK,referencedColumnName =ID)
@ManyToOne(可选= false,fetch = FetchType.LAZY)
私人客户customerFk;
@OneToMany(cascade = CascadeType.ALL,mappedBy =designFk,fetch = FetchType.LAZY)
private List< Product>产品;

通过放置一个断点,我可以看到 cds 列表在EJB端正确检索。第一个问题是,为什么我得到一个Vector而不是List?我使用JPS方面的TypedQuery,它应该能正确地转换对象。





然而,我主要关心的是:在表示层中客户端类本身的后续断点上,它似乎无法完全重建对象,值全为空,而类型丢失。我在这里错过了什么?



< img src =https://i.stack.imgur.com/m0DDg.pngalt =在这里输入图片描述>

解决花了几天的时间努力使它工作,我发现这个SO帖子,它带来了最明显的解决方案,Glassfish和EclipseLink的一个bug !!!



SO帖子:
EclipseLink反序列化远程EJB调用时的空实体对象



错误:
eclipselink.weaving打破开箱即用的封锁


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.

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 ?

解决方案

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

这篇关于JPA实体没有正确地从EJB传递到表示层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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