![](/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.