2012-02-28 68 views
2

我有在Postgres的序列和JPA的Postgres + EJB3預分配大小錯誤

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) 

回答

3

的規則是:序列的增量大小是allocationSize在JPA值: 我有這樣的設置:這是錯誤的:

@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