Hi,
The database i am using is Mysql and Seam 2.2.1.CR2. The table userroles has 2 columns - userid and roleid and both form a composite primary key. In code when i override the update method, it gets executed and returns the Updated status message but the database layer is not updated as no hibernate update sql is generated and nothing appears in the logs. So I think the update query is never generated or possibly ignored by JPA. Need to know as to whats wrong either with the column mapping or the code.
Following are the classes:
-UserRoles Class
@Entity
@Table(name = "user_roles")
public class UserRoles implements java.io.Serializable {
private UserRolesId id;
public UserRoles() {
}
public UserRoles(UserRolesId id) {
this.id = id;
}
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "userId", column = @Column(name = "user_id", nullable = false)),
@AttributeOverride(name = "roleId", column = @Column(name = "role_id", nullable = false))})
@NotNull
public UserRolesId getId() {
return this.id;
}
public void setId(UserRolesId id) {
this.id = id;
}
}
-UserRolesId class
@Embeddable
public class UserRolesId implements java.io.Serializable {
private int userId;
private int roleId;
public UserRolesId() {
}
public UserRolesId(int userId, int roleId) {
this.userId = userId;
this.roleId = roleId;
}
@Column(name = "user_id", nullable = false)
public int getUserId() {
return this.userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
@Column(name = "role_id", nullable = false)
public int getRoleId() {
return this.roleId;
}
public void setRoleId(int roleId) {
this.roleId = roleId;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof UserRolesId))
return false;
UserRolesId castOther = (UserRolesId) other;
return (this.getUserId() == castOther.getUserId())
&& (this.getRoleId() == castOther.getRoleId());
}
public int hashCode() {
int result = 17;
result = 37 * result + this.getUserId();
result = 37 * result + this.getRoleId();
return result;
}
}
-UsersHome Class
@Name("userRolesHome")
public class UserRolesHome extends EntityHome {
public void setUserRolesId(UserRolesId id) {
setId(id);
}
public UserRolesId getUserRolesId() {
return (UserRolesId) getId();
}
public UserRolesHome() {
setUserRolesId(new UserRolesId());
}
@Override
public boolean isIdDefined() {
if (getUserRolesId().getRoleId() == 0)
return false;
if (getUserRolesId().getUserId() == 0)
return false;
return true;
}
@Override
protected UserRoles createInstance() {
UserRoles userRoles = new UserRoles();
userRoles.setId(new UserRolesId());
return userRoles;
}
public void load() {
if (isIdDefined()) {
wire();
}
}
public void wire() {
getInstance();
}
public boolean isWired() {
return true;
}
public UserRoles getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
@Override
public String update() {
....
return super.update();
}
}