Hi,
I'm getting a problem to map exceptions on Hsqldb.
When i'm connected with postgresql for intance, a Unique Key violation returns the constraint name on exception message:
HibernateException.getCause().getNextException()
With this method sequence I get the JDBC driver exception message.
The problem is, Hsqldb with hibernate does not return the JDBC exception message.
Somebody knows what is going on?
Any help is welcome!
Rodrigo G. Tavares de Souza
Brazil - SP
---------------------------------
Detailed explanation
---------------------------------
HsqlDb Version: 1.8
Hibernate: 3.2.4
---------------------------------
This SQL generates a Unique Key exception: insert into produto_classe values (3, 'CLASSE B', 0);
JDBC connection returns the Database message:
Code:
Class.forName("org.hsqldb.jdbcDriver");
Connection conn = DriverManager.getConnection(
"jdbc:hsqldb:hsql://192.168.0.4/kiwi",
"sa", "");
Statement st = conn.createStatement();
st.execute("insert into produto_classe values (3, 'CLASSE B', 0)");
------------------------
Exception in thread "main" java.sql.SQLException: Violation of unique constraint $$: duplicate value(s) for column(s) $$: PRODUTO_CLASSE_UK1
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at br.com.digiarte.kiwi.testes.ProdClasseTeste.main(ProdClasseTeste.java:26)
But hibernate does not:
Code:
SessionFactory.currentSession().beginTransaction();
ProdutoClasseVO vo = new ProdutoClasseVO(3);
vo.setDescricao("CLASSE B");
vo.setClasseA('0');
SessionFactory.currentSession().save(vo);
SessionFactory.currentSession().getTransaction().commit();
------------------------
Hibernate: insert into produto_classe (descricao, classeA, id) values (?, ?, ?)
2007-06-22 16:51:09,093 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
2007-06-22 16:51:09,093 [main] ERROR org.hibernate.util.JDBCExceptionReporter - failed batch
2007-06-22 16:51:09,093 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at br.com.digiarte.kiwi.testes.ProdClasseTeste.main(ProdClasseTeste.java:15)
Caused by: java.sql.BatchUpdateException: failed batch
at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 8 more