This commit is contained in:
Maxime Dagnicourt
2008-01-22 10:15:17 +00:00
parent da5155ebae
commit 133c44e32e
3 changed files with 35 additions and 17 deletions

View File

@@ -2,7 +2,6 @@ package org.yacos.core.users;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
@@ -32,26 +31,31 @@ public class Role implements Serializable {
/** /**
* Dummy field to make the composite PK work despite the ManyToOne relationship * Dummy field to make the composite PK work despite the ManyToOne relationship
*/ */
@Id /*@Id
@Column(name="user_id",insertable=false,updatable=false) @Column(name="user_id",insertable=false,updatable=false)
private String user_id; private String user_id;
*/
/** /**
* User for which this role is defined * User for which this role is defined
* Primary Key * Primary Key
*/ */
@Id
@ManyToOne(targetEntity=User.class,optional=false) @ManyToOne(targetEntity=User.class,optional=false)
@JoinColumn(name="user_id",nullable=false) @JoinColumn(name="user_id",nullable=false)
private User user; private User user;
/** /**
* Dummy field to make the composite PK work despite the ManyToOne relationship * Dummy field to make the composite PK work despite the ManyToOne relationship
*/ */
@Id /*@Id
@Column(name="conference_id",insertable=false,updatable=false) @Column(name="conference_id",insertable=false,updatable=false)
private Integer conference_id; private Integer conference_id;
*/
/** /**
* Conference for which this role is defined * Conference for which this role is defined
* Primary Key * Primary Key
*/ */
@Id
@ManyToOne(targetEntity=Conference.class,optional=false) @ManyToOne(targetEntity=Conference.class,optional=false)
@JoinColumn(name="conference_id",nullable=false) @JoinColumn(name="conference_id",nullable=false)
private Conference conference; private Conference conference;
@@ -87,7 +91,7 @@ public class Role implements Serializable {
@JoinColumn(name="user_id",nullable=false) @JoinColumn(name="user_id",nullable=false)
public void setUser(User user) { public void setUser(User user) {
this.user = user; this.user = user;
this.user_id = user.getLogin(); //this.user_id = user.getLogin();
} }
@ManyToOne(targetEntity=Conference.class,optional=false) @ManyToOne(targetEntity=Conference.class,optional=false)
@@ -101,7 +105,7 @@ public class Role implements Serializable {
@JoinColumn(name="conference_id",nullable=false) @JoinColumn(name="conference_id",nullable=false)
public void setConference(Conference conference) { public void setConference(Conference conference) {
this.conference = conference; this.conference = conference;
this.conference_id = conference.getId(); //this.conference_id = conference.getId();
} }

View File

@@ -1,6 +1,10 @@
package org.yacos.core.users; package org.yacos.core.users;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.yacos.core.conferences.Conference; import org.yacos.core.conferences.Conference;
import org.yacos.core.users.Role.RoleType; import org.yacos.core.users.Role.RoleType;
@@ -14,11 +18,17 @@ public class RolePK implements Serializable{
/** /**
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html * Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
*/ */
public String user_id;
@ManyToOne(targetEntity=User.class,optional=false)
@JoinColumn(name="user_id",nullable=false)
public User user;
/** /**
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html * Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
*/ */
public Integer conference_id;
@ManyToOne(targetEntity=Conference.class,optional=false)
@JoinColumn(name="conference_id",nullable=false)
public Conference conference;
/** /**
* Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html * Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
*/ */
@@ -29,9 +39,10 @@ public class RolePK implements Serializable{
public RolePK(User user, RoleType type, Conference conference) { public RolePK(User user, RoleType type, Conference conference) {
super(); super();
this.user_id = user.getLogin(); this.user = user;
this.type = type; this.type = type;
this.conference_id = conference.getId(); this.conference = conference;
} }
@Override @Override
@@ -41,13 +52,13 @@ public class RolePK implements Serializable{
} }
RolePK otherPK = (RolePK) obj; RolePK otherPK = (RolePK) obj;
return type.equals(otherPK.type)&& return type.equals(otherPK.type)&&
user_id.equals(otherPK.user_id)&& user.equals(otherPK.user)&&
conference_id == otherPK.conference_id; conference == otherPK.conference;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return type.hashCode() ^ user_id.hashCode() ^ conference_id.hashCode(); return type.hashCode() ^ user.hashCode() ^ conference.hashCode();
} }
} }

View File

@@ -4,10 +4,10 @@ import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
@@ -59,7 +59,8 @@ public class User implements Serializable{
/** /**
* Roles for this user * Roles for this user
*/ */
@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER,cascade=CascadeType.ALL) //@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
@OneToMany(targetEntity=Role.class,mappedBy="user")
private List<Role> roles; private List<Role> roles;
@OneToMany(targetEntity=Article.class,mappedBy="mainAuthor") @OneToMany(targetEntity=Article.class,mappedBy="mainAuthor")
@@ -139,7 +140,8 @@ public class User implements Serializable{
return false; return false;
} }
@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER) //@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER)
@OneToMany(targetEntity=Role.class,mappedBy="user")
public List<Role> getRoles(){ public List<Role> getRoles(){
return roles; return roles;
} }
@@ -162,7 +164,8 @@ public class User implements Serializable{
/** /**
* @param roles the roles to set * @param roles the roles to set
*/ */
@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER) //@OneToMany(targetEntity=Role.class,mappedBy="user",fetch=FetchType.EAGER)
@OneToMany(targetEntity=Role.class,mappedBy="user")
public void setRoles(List<Role> roles) { public void setRoles(List<Role> roles) {
this.roles = roles; this.roles = roles;
} }