-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Exception dealing - Hsqldb
PostPosted: Fri Jun 22, 2007 4:18 pm 
Newbie

Joined: Tue Aug 16, 2005 9:21 am
Posts: 12
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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 23, 2007 6:32 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Since you are using the transactions, it will be treated as batch update and hence you see a batch exception being thrown. I guess if you catch the batch exception and get to its root cause, you might be able to see the actual exception.

Or Since you are doing only 1 query you can try creating a session for this single query and close after saving it.

Cheers!
Jitendra


Top
 Profile  
 
 Post subject: Re: Exception dealing - Hsqldb
PostPosted: Sun Nov 18, 2012 8:17 pm 
Newbie

Joined: Wed Jul 05, 2006 3:09 am
Posts: 3
It's also possible to disable batching in hibernate, just set
Code:
hibernate.jdbc.factory_class=org.hibernate.jdbc.NonBatchingBatcherFactory
in your hibernate session configuration (from http://inoio.de/blog/2012/11/16/how-to-get-rid-of-hibernate-genericjdbcexception/ )


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.