简体   繁体   English

Java JPA-实体之间的OneToOne关系不起作用

[英]Java JPA - OneToOne Relation between Entities not working

Licitatie Entity: 合法实体:

@Entity
@Table(name="licitatie")
public class Licitatie implements Serializable {
    ...

    //bi-directional one-to-one association to Licitatie
    @OneToOne(mappedBy="licitatie")
    private Produs produs;

    ...
}

Produs Entity: 产品实体:

@Entity
@Table(name="produs")
//@DiscriminatorColumn(name="id", discriminatorType=DiscriminatorType.INTEGER)
@MappedSuperclass
public class Produs implements Serializable {
    ...

    //bi-directional one-to-one association to Produs
    @OneToOne
    @JoinColumn(name="licitatie_id")
    private Licitatie licitatie;

    ...
}

Database: 数据库:

Licitatie: 合法:

id  start   status
1   5   open
2   5   open
3   5   open

Produs: 产品:

id  licitatie_id    DTYPE   description
1   1           Carte   ...
2   2           Carte   ...
3   3           Carte   ...

After I run tris query: "SELECT t FROM Licitatie t" , the attribute Product from object of type Licitatie is null. 在我运行tris查询后: “ SELECT t FROM Licitatie t” ,类型为Licitatie的对象的Product属性为null。 But there are records in tables. 但是表中有记录。

What I'm doing wrong? 我做错了什么?

* EDIT * *编辑*

After I get data from table, calling getProdus() return this message: 从表中获取数据后,调用getProdus()返回此消息:

{IndirectSet: not instantiated} {IndirectSet:未实例化}

SOLVED 解决了

I've added column PRODUS_ID to licitatie table. 我已将列PRODUS_ID添加到许可证表中。

Licitatie: id produs_id ... Produs: id, licitatie_id ... 合法:id produs_id ...产品:id,licitatie_id ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM