Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Value of Column is null while Deleting in ManyToMany-Relationship
Value of Column is null while Deleting in ManyToMany-Relationship [message #1045022] Fri, 19 April 2013 16:54 Go to next message
Manuel Frick is currently offline Manuel Frick
Messages: 3
Registered: April 2013
Junior Member
Hello everyone,

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 a 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

The 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 



Re: Value of Column is null while Deleting in ManyToMany-Relationship [message #1046888 is a reply to message #1045022] Mon, 22 April 2013 13:56 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1033
Registered: July 2009
Senior Member
"ACCOUNTID" is the primary key for the entity, and JPA only allows using the primary key in references and should be giving you validation errors. You can try turning on Logging to see if you are getting warnings or other messages during start up/deployment as described here: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging

I suspect there are problems with your entity design though, as I do not see how "Account_accountId" can be used both as the "UserAccount" table foreign key to its "Account" table row (as described in the @PrimaryKeyJoinColumn) and as a foreign key for a OneToOne mapping to an Account entity - this implies it has a relationship to itself, since the row in the "Account" table with that value represents a UserAccount entity. Joined table inheritance you have setup means that UserAccount entities span both the "UserAccount" and "Account" tables, so I believe this mapping should be removed.

The reference table should also point to the entities primary key, which is the Account.accountId field, and should be enough to uniquely identify the entity without the use of the email.


Previous Topic:Sporadic and arbitrary DELETES issued by EclipseLink
Next Topic:EclipseLink NoSQL support, limitations and future plans?
Goto Forum:
  


Current Time: Wed Oct 22 08:18:54 GMT 2014

Powered by FUDForum. Page generated in 0.02160 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software