@ManyToMany: Why columns order in primary key depends on entity class names? [message #1814577] |
Fri, 13 September 2019 13:31  |
Oleg Shchukin Messages: 1 Registered: September 2019 |
Junior Member |
|
|
I use Eclipselink 2.7.4 and try to create a simple bidirectional many-to-many mapping:
@Entity
@Table(name = "Users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String username;
@ManyToMany
private Set<Role> roles = new HashSet<>();
}
@Entity
public class Role {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String rolename;
@ManyToMany(mappedBy = "roles")
private Set<User> users = new HashSet<>();
}
With theese entities Eclipselink generates this relation table:
CREATE TABLE Users_ROLE (roles_ID INTEGER NOT NULL, users_ID INTEGER NOT NULL, PRIMARY KEY (roles_ID, users_ID));
Note columns order in the primary key (and it seems to me this order is incorrect).
If I change the class name `User` to `AppUser` (I change only the class name, its table name remain the same - "Users"), then Eclipselink generates:
CREATE TABLE Users_ROLE (users_ID INTEGER NOT NULL, roles_ID INTEGER NOT NULL, PRIMARY KEY (users_ID, roles_ID));
What I see is the primary key columns order depends on the alphabetical name of entity classes instead of the mappedBy attribute:
- in first case `Role`, `User`;
- in second case `AppUser`, `Role`.
And also a primary key doesn't change if I move `mappedBy` attribute from `Role` to `User`.
Is it a bug or a feature?
|
|
|
|
Powered by
FUDForum. Page generated in 0.01860 seconds