Trying to implement Spring Security and cannot map roles and users. So I have "users", "roles" and "user_role_connector" database tables:
CREATE TABLE users (
user_pk INT NOT NULL AUTO_INCREMENT,
...
PRIMARY KEY (user_pk));
CREATE TABLE roles (
role_pk INT NOT NULL AUTO_INCREMENT,
role VARCHAR(20) NOT NULL UNIQUE,
PRIMARY KEY (role_pk));
CREATE TABLE user_role_connector (
urc_pk INT NOT NULL AUTO_INCREMENT,
user_fk INT NOT NULL,
role_fk INT NOT NULL,
FOREIGN KEY (user_fk) REFERENCES users(user_pk),
FOREIGN KEY (role_fk) REFERENCES roles(role_pk),
PRIMARY KEY (urc_pk));
And I have Entity classes for Role and User. Both work until I add in mapping:
@Entity
@Table(name = "users")
public final class UserAccount {
private int user_pk;
...
@OneToOne(cascade=CascadeType.ALL)
@JoinTable(name = "user_role_connector",
joinColumns = {@JoinColumn(name = "user_fk", referencedColumnName = "user_pk")},
inverseJoinColumns = {@JoinColumn(name = "role_fk", referencedColumnName = "role_pk")}
)
private Role role;
@Entity
@Table(name = "roles")
final public class Role {
private int role_pk;
private String role;
@OneToMany(cascade=CascadeType.ALL)
@JoinTable(name="user_role_connector",
joinColumns = {@JoinColumn(name="role_fk", referencedColumnName="role_pk")},
inverseJoinColumns = {@JoinColumn(name="user_fk", referencedColumnName="user_pk")}
)
private Set<UserAccount> userRoles;
Why wont it map? Errors that come are bean creating errors from the alphabetically first controller so it must be bad mapping.
And is there any good Spring Security tutorial out there?
EDIT: Forgot to write that the classes work untill the "role" field to userAccount and userRoles to role is added. And only the code with error is displayd here. Sry for bad english.