2013-10-09 57 views
1

我們使用Hibernate和JPA註釋,配置如下所示。當我們使用GenerationType.AUTO時,忽略allocationSize,休眠日誌顯示每個insert的sequence.nextval。Hibernate @SequenceGenerator分配大小由JPA忽略GenerationType.AUTO

將其更改爲GenerationType.SEQUENCE,如下所述按預期工作。但這不適用於其他數據庫。這是一個錯誤?還是有一些其他配置需要設置?

@Id 
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MYOBJ_SEQ") 
@SequenceGenerator(name = "MYOBJ_SEQ", sequenceName = "MYOBJ_SEQ", allocationSize = 100) 
@Column(name = "MYOBJ_PK", length = 11) 
private Integer id; 

回答

0

最靈活和可移植的方式產生標識符是使用一個數據庫表,例如:

@Id 
@GeneratedValue(strategy = GenerationType.TABLE, generator = "id_generator") 
@TableGenerator(allocationSize = 100, name = "id_generator") 
@Column(name = "MYOBJ_PK", length = 11) 
private Integer id;