【问题标题】:Postgres + EJB3 pre-allocation size errorPostgres + EJB3 预分配大小错误
【发布时间】:2012-03-17 16:36:43
【问题描述】:

我在 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)

【问题讨论】:

    标签: ejb-3.0 jpa-2.0 glassfish-3 postgresql-9.1


    【解决方案1】:

    尝试将序列的起始值设置为至少与您用于 @SequenceGenerator 注释的属性 allocationSize 的大小相同。

     CREATE SEQUENCE seq_name
     ...
     START WITH 100;
    

    详情请参阅http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg03461.html

    【讨论】:

      【解决方案2】:

      规则是:序列的增量大小是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
      

      【讨论】:

        猜你喜欢
        • 2018-12-13
        • 2014-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-11
        • 2014-03-14
        相关资源
        最近更新 更多