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:
When we want to save a Object in the DB, and we got this error:
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
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.
There is a good explanation about this random error?
Sequence:
--
-- ORDER_SEQ (Sequence)
--
CREATE SEQUENCE rommDBA.ORDER_SEQ
START WITH 1
MAXVALUE 9999999999999999999999999999
MINVALUE 1
NOCYCLE
NOCACHE
ORDER
NOKEEP
GLOBAL;
Table:
--
-- 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;
Model Class:
@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;
}
EDIT, more config Info:
<!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 Config:
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");
Connection String:
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)))