Hibernate 4.2.21 ORA-00001: unique constraint
<p>I'm working with Hibernate 4.2.21.Final and Oracle Database 12c 12.1.0.2.0 - 64bit Production, we have defined in our Jboss a JNDI for our DataSource, We have a strange problem in one of our Tables - only in this case, this problem it's not usual may be we have in total 2 cases during this two weeks:</p>

<p>When we want to save a Object in the DB, and we got this error:</p>

<pre><code>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
</code></pre>

<p>This constraint it's a Primary Key, the problem seems to be we are using a primary key that it's in use, but if this fail should be fail more times, when I try to save the Object the second time works.</p>

<p>There is a good explanation about this random error?</p>

<p>Sequence:</p>

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

<p>Table:</p>

<pre><code>--
-- 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;
</code></pre>

<p>Model Class:</p>

<pre><code>@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;
</code></pre>

<p>DAOImpl:</p>

<pre><code> 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;
        }
</code></pre>

<p>EDIT, more config Info:</p>

<pre><code>&lt;!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd"&gt;
&lt;hibernate-configuration&gt;
   &lt;session-factory&gt;

      &lt;property name="hibernate.jdbc.batch_size"&gt;30&lt;/property&gt;
      &lt;property name="hibernate.default_schema"&gt;rommApp&lt;/property&gt;
      &lt;mapping class="backend.model.romm.Order" /&gt;

   &lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</code></pre>

<p>SessionFactory Config:</p>

<pre><code>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");
</code></pre>

<p>Connection String:</p>

<pre><code>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)))
</code></pre>