【问题标题】:Specifying the intermediate table name in JPA OneToMany relationship在 JPA OneToMany 关系中指定中间表名
【发布时间】:2012-07-24 18:00:36
【问题描述】:

我有一个表用户,每个用户都有一组其他用户作为朋友。我在模型类中定义它的方式如下:

     Public class User extends Models {
     ....
     @OneToMany
     public List<User> friends;
     .
     .
     }

现在 Play JPA 正在创建一个中间表名 user_user 具有以下字段。

    mysql> desc user_user;
    ------------+------------+------+-----+---------+-------+
    | user_id     | bigint(20) | NO   | MUL | NULL    |       |
    | friends_id  | bigint(20) | NO   | PRI | NULL    | 

问题是如何更改中间表 (user_user) 的名称和其中的列?

【问题讨论】:

    标签: jpa playframework


    【解决方案1】:

    使用 @JoinTable 注释应该可以满足您的需求。有一篇很好的帖子 (JPA "@JoinTable" annotation) 专门介绍了如何使用此注释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 2017-01-23
      • 1970-01-01
      • 2021-06-15
      • 2020-11-03
      • 2023-03-20
      • 2010-10-27
      相关资源
      最近更新 更多