1

我有这两张桌子..

用户

  • ID
  • 用户名(可为空=真)
  • 全名

评论

  • ID
  • user_id (fk)
  • 文本

我想从用户表中检索带有属性的评论,就像这样..

公共类评论{

私人长ID;

私人长用户名;

…</p>

}

4

1 回答 1

3

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;
   }
于 2013-11-14T06:49:25.103 回答