Java JPA - 实体之间的一对一关系不起作用
Licitatie 实体:
@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
@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;
...
}
数据库:
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 ...
在我运行 tris 查询后:“SELECT t FROM Licitatie t”,属性 Product来自 Licitatie 类型的对象为 null。但表中有记录。
我做错了什么?
* 编辑*
从表中获取数据后,调用 getProdus() 返回此消息:
{ IndirectSet:未实例化}
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. But there are records in tables.
What I'm doing wrong?
* EDIT *
After I get data from table, calling getProdus() return this message:
{IndirectSet: not instantiated}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决
我已将 PRODUS_ID 列添加到 licitatie 表中。
许可: id produs_id ...
产品:id、licitatie_id ...
SOLVED
I've added column PRODUS_ID to licitatie table.
Licitatie: id produs_id ...
Produs: id, licitatie_id ...