一对多关系始终为空

One to Many relations is always null

给定以下 SQL 模型:

Two Views
   VIEW PRODUCT
       ID_PROPOSAL
       ID_PRODUCT

   VIEW PERSON
       ID_ENTITY
       ID_PRODUCT
       NAME

JPA
@NamedQueries({
        @NamedQuery(name = "Product.getByProposalId",
                query = "SELECT ie "
                        + "FROM Product ie "
                        + "WHERE ie.idProposal = :proposalId ")
}) 
 @Entity
 Table(name = "PRODUCT")
 public classe Product{

    @Id
    @Column(name = "ID_PRODUCT")
    private Long idProduct;

    @Column(name = "ID_PROPOSAL")
    private Long idProposal;

     @OneToMany(mappedBy="product")
     List<Person> persons;

      public List<Person> getPersons() {
        return persons;
      }

      public void setPersons(List<Person> persons) {
        this.persons= persons;
      }

}

 @Entity
 Table(name = "PERSON")
 public classe Person{

    @Id
    @Column(name = "ID_ENTITY")
    private Long idEntity;

    @Column(name = "ID_PRODUCT")
    private Long idProduct;

     @ManyToOne
     @JoinColumn(name = "ID_PRODUCT", insertable = false, updatable = false)
     Product product;

      public List<Person> getPersons() {
        return persons;
      }

      public void setPersons(List<Person> persons) {
        this.persons= persons;
      }

}


 Query query = emanager.createNamedQuery("Product.getByProposalId");
        query.setParameter("propostaId", proposalId);
        return query.getResultList();

它 return 是正确的产品结果,但是每个产品都没有 return 任何人,在日志文件中我看不到对查看人的任何查询。 应用服务器为websphere,jpa实现为openjpa1.2.3

有什么想法吗? 提前致谢 最好的问候

既然你已经确认问题出在 Lazy loading,我已经评论过了,我想把它添加为答案。这样这对以后来这里的人会有帮助post。

您必须使用 FetchType.EAGERonetomany 中的 lazy loading 配置为 false,如下所示。

@OneToMany(fetch=FetchType.EAGER)

如果您没有指定,默认情况下延迟加载将是 true