Note that there are some explanatory texts on larger screens.

plurals
  1. POEclipseLink: Value of Column is null while Deleting in ManyToMany-Relationship
    text
    copied!<p>I have a problem with one of my entities.</p> <p>There are 3 Tables (UserAccount, UserRole, Role) for Glassfish Access Management and two Entities UserAccount and Role mapped by "ManyToMany" to each other.</p> <p>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:</p> <pre><code>INSERT INTO UserRole (Role_roleName, UserAccount_email, UserAccount_Account_accountId) VALUES ('Client', 'email@example.com', 1) </code></pre> <p>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".</p> <pre><code>DELETE FROM UserRole WHERE ((Role_roleName = 'Administrator') AND ((UserAccount_Account_accountId = 1) AND (UserAccount_email = null))) </code></pre> <p>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...</p> <p>Any Help is very appreciated.</p> <p>Thanks, Manuel</p> <p>Setup: Container: Glassfish 3.1.2 JPA: Eclipse Persistence Services - 2.3.2.v20111125-r10461</p> <p>UserAccount entity:</p> <pre><code>@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&lt;Role&gt; roles; //getter and setters </code></pre> <p>Account Entity</p> <pre><code>@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 </code></pre> <p>Role Entity:</p> <pre><code>@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&lt;UserAccount&gt; userAccounts; //getter and setters </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload