Specifying a staging table name for JPA OneToMany

I have a table user, and each user has a set of other users as friends. The way I defined it in my model class is this:

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

Play JPA now creates the staging table name user_user with the following fields.

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

Question: how can I change the name of the staging table (user_user) and the columns in it?

+5
source share
1 answer

Using annotations @JoinTableshould give you what you need. There is a good publication ( JPA "@JoinTable" annotation ), in particular, on how to use this annotation.

+7
source

All Articles