我有这两张桌子..
用户
- ID
- 用户名(可为空=真)
- 全名
评论
- ID
- user_id (fk)
- 文本
我想从用户表中检索带有属性的评论,就像这样..
公共类评论{
私人长ID;
私人长用户名;
…</p>
}
You can very well use the concept of secondary table
This will allow you to achieve the above mentioned case. Like given below:
@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;
}