JBoss 6 - hibernate/jpa/oracle issues
pskrzynski Jan 25, 2011 9:26 AMHello,
I've got an application which is deployed on JBoss M3 and has been working perfectly well on it. However when I try to migrate to final release the same application does not work. The problem is that whenever I try to save the record in the Oracle database through JPA and I call persist method on entity manager I receive an exception:
13:10:45,182 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96) [:3.6.0.Final]
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [:3.6.0.Final]
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) [:3.6.0.Final]
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114) [:3.6.0.Final]
...
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (GETIN8.REQUEST_PARAMETER_PK) violated
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:345) [:Oracle JDBC Driver version - "10.2.0.5.0"]
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10844) [:Oracle JDBC Driver version - "10.2.0.5.0"]
at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:774) [:6.0.0.Final]
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) [:3.6.0.Final]
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) [:3.6.0.Final]
... 73 more
13:10:45,184 WARN [com.arjuna.ats.arjuna] ARJUNA-12125 TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffc0a8167a:397a:4d3eb67d:2e6, org.hibernate.transaction.synchronization.HibernateSynchronizationImpl@68538fd0 >: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
The problem is that when I create an object and try to save it, the id of the object is obtained through sequence. And calling nextval on Oracle sequence through JPA does not work correctly since it returns the id that is already busy, look:
13:10:45,110 INFO [test] Saving object: Request [requestId=0, operationName=login, userId=12345678, operationDate=Tue Jan 25 13:10:45 CET 2011]
13:10:45,111 INFO [test] Object saved: Request [requestId=11349, operationName=login, userId=12345678, operationDate=Tue Jan 25 13:10:45 CET 2011]
In the JBoss 6 M3 tha same sequence return values greter by ~30 which is correct. I've just noticed that tha same application and the same JBoss configuration in M3 outputs:
13:08:31,338 INFO [test] Saving object: Request [requestId=0, operationName=login, userId=12345678, operationDate=Tue Jan 25 13:08:31 CET 2011]
13:08:31,408 INFO [STDOUT] Hibernate: select request_request_id_seq.nextval from dual
13:08:31,415 INFO [test] Object saved: Request [requestId=11386, operationName=login, userId=12345678, operationDate=Tue Jan 25 13:08:31 CET 2011]
So as you see the sequence value is obtained through Hibernate through expected SQL query. In final release Hibernate does not print this query to the output despite the fact that in both cases it later prints the insert query in the same manner:
13:10:45,158 INFO [STDOUT] Hibernate: insert into request (operation_date, operation_name, user_id, request_id) values (?, ?, ?, ?)
I annotate the requestId attribute in the Request class like this:
@Id
@Column(name = "request_id")
@GeneratedValue(generator="request_increment")
@SequenceGenerator(name="request_increment", sequenceName = "request_request_id_seq")
public long getRequestId() {
return requestId;
}
Any hints how to make it work on final release? Thanks for help.
Pawel