Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » (no subject)
(no subject) [message #691891] Sat, 02 July 2011 17:50
Eclipse UserFriend
Originally posted by: <forums-noreply

Hi, I'm Pal, and I keep getting a strange error. :)

I want to create custom JAAS authentication where my users and principals relationships are defined in JPA as shown:

class AuthUser

public class AuthUser implements Serializable {

// own properties
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private int uid;

@Column(name="NAME",unique=true)
private String name;

// Join classes
@ManyToMany(fetch=FetchType.EAGER,cascade={CascadeType.MERGE})
@JoinColumn(name="PRINCIPALS_PRINCIPAL")
private Set<AuthPrincipal> principals;
}

class AuthPrincipal

public class AuthPrincipal implements Serializable {

// Defining roles
public enum Principal {
AUTHUSER, STUDENT, ADMINISTRATOR, TEACHER
}

@Id
@Enumerated(EnumType.STRING)
@Column(name="PRINCIPAL")
private Principal principal;

@ManyToMany(mappedBy = "principals")
@JoinColumn(name="USERS_USER")
private Set<AuthUser> users;
}

Maps to the following Table definition

Table authprincipal
===================
PRINCIPAL varchar(255) PK

Table authuser
==============
UID int(11) PK
EMAIL varchar(255)
NAME varchar(255)
PASSWORD varchar(255)

Table authuser_authprincipal
============================
users_UID int(11) PK
principals_PRINCIPAL varchar(255) PK

Now, I created a JSF file from which I call an action method that calls this one:

public void createUser(AuthUser newUser) throws UserNameExistsException, UserEmailExistsException {
AuthPrincipal role = authRoleFacade.find(AuthPrincipal.Principal.AUTHUSER);
if( role == null ){
role = new AuthPrincipal();
role.setPrincipal(AuthPrincipal.Principal.AUTHUSER);
authRoleFacade.create(role);
}
authUserFacade.create(newUser);
addPrincipalToUser(newUser, role);
}


The actual problem
I can create the first user. But I can't create the second user . Notice that at the second user I use the existing role object, and only cascade a merge operation, I don't know if it mattress.

The strangest thing is that it says it duplicates the 2-AUTHUSER key where 2 is the id of the new user so cannot already be in the join table. What is wrong with it or with Eclipselink or with Me?

The error what eclipselink throws

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '2-AUTHUSER' for key 'PRIMARY'
Error Code: 1062
Call: INSERT INTO AUTHUSER_AUTHPRINCIPAL (principals_PRINCIPAL, users_UID) VALUES (?, ?)
bind => [2 parameters bound]
Query: DataModifyQuery(name="principals" sql="INSERT INTO AUTHUSER_AUTHPRINCIPAL (principals_PRINCIPAL, users_UID) VALUES (?, ?)")
jpa many-to-many duplicates eclipselink duplicate-entry
Previous Topic:(dupliacte, ignore)
Next Topic:Programmatically obtain SQL statements emitted by EclipseLink
Goto Forum:
  


Current Time: Fri Mar 29 04:52:47 GMT 2024

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

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

Back to the top