Hibernate 4.2.21 ORA-00001:唯一约束

时间:2016-05-24 07:54:56

标签: java oracle hibernate jpa java-ee

我正在使用Hibernate 4.2.21.Final和Oracle Database 12c 12.1.0.2.0 - 64bit Production,我们在Jboss中为我们的DataSource定义了一个JNDI,我们在其中一个表中有一个奇怪的问题 - 只有在这种情况下,这个问题并不常见,在这两周内我们总共有2例:

当我们想在DB中保存一个Object时,我们收到了这个错误:

2016-05-24 08:16:30,425 INFO
[org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl] (rommApp)
HHH000010: On release of batch it still contained JDBC statements

2016-05-24 08:16:30,427 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (rommApp) SQL
Error: 1, SQLState: 23000 2016-05-24 08:16:30,427 ERROR
[org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (rommApp)
ORA-00001: unique constraint (rommDBA.SYS_C006240) violated

这个约束它是一个主键,问题似乎是我们正在使用它正在使用的主键,但如果这个失败应该失败多次,当我尝试第二次保存Object时。

关于这个随机错误有一个很好的解释?

序列:

--
-- ORDER_SEQ  (Sequence)
--
CREATE SEQUENCE rommDBA.ORDER_SEQ
  START WITH 1
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  NOCACHE
  ORDER
  NOKEEP
  GLOBAL;

表:

--
-- ORDERS  (Table)
--
CREATE TABLE ROMMDBA.ORDERS
(
  ORDER_ID                 NUMBER(19)           NOT NULL,
  ORDER_NAME                VARCHAR2(255 CHAR),
  ORDER_CREATEDBY          VARCHAR2(255 CHAR)   NOT NULL,
  ORDER_CREATEDON          TIMESTAMP(6)         NOT NULL,
)
TABLESPACE ROMM
RESULT_CACHE (MODE DEFAULT)
PCTUSED    40
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          1M
            NEXT             1M
            MAXSIZE          UNLIMITED
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
            FLASH_CACHE      DEFAULT
            CELL_FLASH_CACHE DEFAULT
           )
LOGGING
COMPRESS FOR OLTP
NOCACHE
NOPARALLEL
MONITORING;

模特课程:

@Id
    @SequenceGenerator(name = "OrderSequence", sequenceName = "order_seq", allocationSize=1)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="OrderSequence")    
    @Column(name = "order_id", unique = true, nullable = false)
    private Long id;

DAOImpl:

 public Order  addOrder(Order order) {
            Session session = SessionFactory.getSessionFactory().openSession();
            try {
                session.beginTransaction();
                session.save(order);
                session.getTransaction().commit();
            } catch (HibernateException e) {
                session.getTransaction().rollback();
                throw new HibernateException(e);
            } finally {
                session.close();
            }

            return order;
        }

编辑,更多配置信息:

<!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>

      <property name="hibernate.jdbc.batch_size">30</property>
      <property name="hibernate.default_schema">rommApp</property>
      <mapping class="backend.model.romm.Order" />

   </session-factory>
</hibernate-configuration>

SessionFactory配置:

configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
configuration.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
configuration.setProperty("hibernate.connection.datasource", "jdbc/rommApp");

连接字符串:

jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=OFF)(FAILOVER=ON)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=XXXXXX)(Port=XXXX))(ADDRESS=(PROTOCOL=TCP)(Host=XXXXXX)(Port=XXXX)))(CONNECT_DATA=(SERVICE_NAME=XXXXX)))

0 个答案:

没有答案