[jboss-user] [EJB 3.0] - Compound key in combination with the generatedValue
mnouwens@future-earth.eu
do-not-reply at jboss.com
Thu Aug 2 10:35:05 EDT 2007
Hello I am creating an entity user which hold an compound primairy key. consisting of id and department_id. The department_id is set by the code but the id should be generated by the Table Generator. BUt this value stay -1.
Can any one point me where it could go wrong.
At the moment i have:
@Entity
@IdClass(UserEntityPk.class)
@Table(name = "KIEKEBOE_USERS")
public class UserEntity implements java.io.Serializable {
@TableGenerator(name = "userIdGen", table = "KIEKEBOE_SEQUENCE_GENERATOR", pkColumnName = "GEN_KEY", valueColumnName = "GEN_VALUE", pkColumnValue = "USER_ID", initialValue = 203, allocationSize = 1)
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "userIdGen")
@Column(name = "USER_ID", nullable = false)
private int id = -1;
@Id
@Column(name = "DEP_ID", nullable = false)
private int depId = -1;
public int getId() {
return id;
}
public int getDepId() {
return depId;
}
The Pk class is:
@Embeddable
public class UserEntityPk implements Serializable {
private int id = -1;
private int depId = -1;
public UserEntityPk() {
super();
}
@Id
@Column(name = "DEP_ID", nullable = false)
public int getDepId() {
return depId;
}
@TableGenerator(name = "userIdGen", table = "KIEKEBOE_SEQUENCE_GENERATOR", pkColumnName = "GEN_KEY", valueColumnName = "GEN_VALUE", pkColumnValue = "USER_ID", initialValue = 203, allocationSize = 1)
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator = "userIdGen")
@Column(name = "USER_ID", nullable = false)
public int getId() {
return id;
}
public void setDepId(int newDepId) {
depId = newDepId;
}
public void setId(int newId) {
id = newId;
}
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4070135#4070135
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4070135
More information about the jboss-user
mailing list