I have a problem with one of my entities.
There are 3 Tables (UserAccount, UserRole, Role) for Glassfish Access Management and two Entities UserAccount and Role mapped by "ManyToMany" to each other.
To change the roles of an UserAccount, I apply a new List of chosen Roles via the setRoles()-Method of UserAccount. When I add new roles, everything works fine, the statement is correct:
INSERT INTO UserRole (Role_roleName, UserAccount_email,
UserAccount_Account_accountId)
VALUES ('Client', 'email@example.com', 1)
But when I remove an item from the list, the removed entry in the join table should also be removed. As expected, there is the query submitted but with the email column set to "null".
DELETE FROM UserRole WHERE ((Role_roleName = 'Administrator')
AND ((UserAccount_Account_accountId = 1) AND (UserAccount_email = null)))
Has anybody an idea why this column is set to null? When I output the email with userAccount.getEmail() right after and before the merge to the database, it returns the email adress...
Any Help is very appreciated.
Thanks, Manuel
Setup: Container: Glassfish 3.1.2 JPA: Eclipse Persistence Services - 2.3.2.v20111125-r10461
UserAccount entity:
@Entity
@Table(name="UserAccount")
@PrimaryKeyJoinColumn(name = "Account_accountId")
public class UserAccount extends Account implements Serializable {
private static final long serialVersionUID = 1L;
private String password;
//bi-directional one-to-one association to Account
@OneToOne
@JoinColumn(name="Account_accountId")
private Account account;
@Column(name="email")
private String email;
//bi-directional many-to-many association to Role
@ManyToMany
@JoinTable(
name="UserRole"
,
joinColumns={
@JoinColumn(name="UserAccount_email", referencedColumnName="email"),
@JoinColumn(name="UserAccount_Account_accountId", referencedColumnName="Account_accountId")
}
, inverseJoinColumns={
@JoinColumn(name="Role_roleName")
}
)
private List<Role> roles;
//getter and setters
Account Entity
@Entity
@Table(name="Account")
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Account implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int accountId;
private boolean active;
private String address;
private String dtype;
private String firstname;
private String handy;
private String name;
private String tel;
//getter and setters
Role Entity:
@Entity
@Table(name="Role")
public class Role implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String roleName;
@Lob
private String roleDescription;
//bi-directional many-to-many association to UserAccount
@ManyToMany(mappedBy="roles")
private List<UserAccount> userAccounts;
//getter and setters