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 as following:
Public class User extends Models {
....
@OneToMany
public List<User> friends;
.
.
}
Now the Play JPA is creating an intermediate table name user_user with following fields.
mysql> desc user_user;
------------+------------+------+-----+---------+-------+
| user_id | bigint(20) | NO | MUL | NULL | |
| friends_id | bigint(20) | NO | PRI | NULL |
Question is how can i change the name of the intermediate table (user_user) and columns in it?
You can have as many of them as you want.
The One-To-Many mapping comes into the category of collection-valued association where an entity is associated with a collection of other entities. Hence, in this type of association the instance of one entity can be mapped with any number of instances of another entity.
Unidirectional @OneToMany with @JoinColumn.
In JPA we use the @ManyToMany annotation to model many-to-many relationships. This type of relationship can be unidirectional or bidirectional: In a unidirectional relationship only one entity in the relationship points the other. In a bidirectional relationship both entities point to each other.
Using the @JoinTable
annotation should give you what you need. There is a good post ( JPA "@JoinTable" annotation ) specifically on how to use this annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With