1

how to store list of values in database ,with a primarykey autoincrement my dao have this primary key

@Id
@GeneratedValue(generator = "increment")
@Column(name = "ParamKey")
public long getParamKey() {
    return paramKey;
}

public void setParamKey(long paramKey) {
    this.paramKey = paramKey;
}

it is inserting for one row and it is showing the exception

java.lang.RuntimeException: a different object with the same identifier value was already associated with the session: 
4

4 回答 4

0

尝试在类中设置你的主键,它代表你的表

@Id
@GeneratedValue
private long id;
于 2013-05-27T08:22:40.543 回答
0

将您的代码更改为:

//Declaration
@Id
@GenericGenerator(strategy = "increment")
@Column(name = "ParamKey")
private int paramKey;

//Getter
public long getParamKey(){
    return paramKey;
}
于 2013-05-27T08:21:32.333 回答
0

检查id表中的列是否autoincrement具有true. (例如,在 MySQL GUI 中)然后使用AUTO前面描述的生成类型。

于 2013-05-27T08:27:38.180 回答
0

这可能是问题所在:-

实际上,当您部署应用程序时,休眠存储最大 id并不断将其增加 1。但同时,如果您直接将值插入数据库,则会导致问题,因为您的休眠不知道这件事。

因此,在下一次插入时,它将 sequence_id+1 分配给下一行,但它已经存在于数据库中,因此它会给您主键约束错误。

于 2013-05-27T08:32:37.107 回答