![](/img/trans.png)
[英]How can I retrieve the foreign key from a JPA ManyToOne mapping without hitting the target table?
[英]JPA mapping - Retrieve attribute from a different table
我有這兩張桌子..
用戶
評論
我想從用戶表中檢索帶有屬性的注釋,就像這樣..
公共課評論{
私人長身份;
私人長用戶名;
...
}
您可以很好地使用輔助表的概念
這將使您實現上述情況。 如下所示:
@Entity
@Table(name = "comment")
@SecondaryTable(name = "user", pkJoinColumns=@PrimaryKeyJoinColumn(name="id", referencedColumnName="id"))
public class Comment {
@Id
@Column(name="id")
private Long commentId;
@Column(table="user", name="username")
private Long userName;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.