hibernate uuid id生成策略问题
大家有没遇到这样的问题啊,我用uuid的主键生成策略,修改数据的时候变成了新增,不知道怎么解决,哪位大神帮解决下。代码如下:
//JPA 基类的标识@MappedSuperclasspublic abstract class PkidEntity { /** * 主键及主键生成方式 */ @Id @GenericGenerator(name="hibernate-uuid",strategy="uuid") @GeneratedValue(generator="hibernate-uuid") @Column(name="pkid", nullable=false) protected String pkid; public String getPkid() { return pkid; } public void setPkid(String pkid) { this.pkid = pkid; } }
@MappedSuperclasspublic abstract class IdEntity { protected Long id; @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PKGen") @SequenceGenerator(name = "PKGen", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1) public Long getId() { return id; } public void setId(Long id) { this.id = id; }}
@Id @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") public String getId() { return this.id; } public void setId(String id) { this.id = id; }
[解决办法]
看了下,原来你是用ORACLE数据库的序列自增的,你就用@SequenceGenerator
[解决办法]