我在postgres和jpa中遇到序列问题
Caused by: javax.persistence.EntityExistsException:
Exception Description: The sequence named [shp_users_seq] is setup incorrectly. Its increment does not match its pre-allocation size.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:443)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:269)
at base.data.provider.beans.session.DAOImpl.createUser(DAOImpl.java:18)
答案 0 :(得分:3)
规则是:序列的增量大小是jpa中allocationSize的值: 我有这样的设置:这是错误的:
@SequenceGenerator(name = "User_Seq_Gen",
sequenceName = "shp_users_seq", allocationSize=999)
根据这个纠正:
@SequenceGenerator(name = "User_Seq_Gen",
sequenceName = "shp_users_seq" ,allocationSize=1)
因为序列的增量大小为1:
shopper=> \d shp_users_seq;
Sequence "public.shp_users_seq"
Column | Type | Value
---------------+---------+---------------------
sequence_name | name | shp_users_seq
last_value | bigint | 1
start_value | bigint | 1
increment_by | bigint | 1
max_value | bigint | 9223372036854775807
min_value | bigint | 1
cache_value | bigint | 1
log_cnt | bigint | 0
is_cycled | boolean | f
is_called | boolean | t
答案 1 :(得分:0)
尝试将序列的起始值设置为至少与用于 @SequenceGenerator 注释的属性 allocationSize 的大小相同。
CREATE SEQUENCE seq_name
...
START WITH 100;
有关详细信息,请参阅http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg03461.html。