-->
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.  [ 1 post ] 
Author Message
 Post subject: Detect/Recover problems in sessions with exceptions
PostPosted: Wed Feb 14, 2007 7:18 am 
Newbie

Joined: Wed Feb 14, 2007 5:30 am
Posts: 1
Hello, i am a newbie on hibernate and i have some doubts that i cant resove completely by reading the docs and forum. Im using hibernate
with spring, but i think my issues are mostly related with hibernate sesssions ans exceptions.

Scenario: Im using global transactions (JTA) with ActiveMQ and MySql-SQLServer. My service method (onMessage), made transactional declaratively,
is responsible for read a message from the queue and generate some records: one record in a master table and n records in a 'details' table.
I need the method to be able to recover or detect problems in the details, and logging them, but without spoiling the entire transaction.

Initially i got problems comitting te transaction in the spring proxy, so i had to use the eager flush mode, at least to get the errors in my code.
And switched to hibernate local trnasactions to not get stuck qith the same message.
I've read that hibernate strongly advice to discard the session once a exception occurs but...

- When two details identical are repeated the session detects the problem and raise and exception. This is ok, y catch it and the transction finishes correctly.
- When two details with a single uppercase difference in a varchar of the compound key are saved, hibernate session dont notice the problem and data controller raise an exception.
- When is saved a detail with a string longer than its correspondant varchar in the key, session doesnt notice either and data controller raise an exception.

In the second and third cases i can catch the exception but the session apparently is left inconsistent; each subsequent operation will throw the
same exception, even saving different details. I have tried to 'evict' the problematic detail from the session, but this operation raise again the
same exception.

I there a workaround to this? I think this scenario is quite normal, so what is the correct approach? Is the only solution to open a new session
and redo all the operations?

Hope Im not missing some elementary concept. Any advice would be highly apreciated.
Thanks in advance and sorry for my english.

Hibernate version: 3.2.0


Full stack trace of any exception that occurs:
Code:
13-02@13:07:42 WARN  (JDBCExceptionReporter.java:71)     - SQL Error: 1062, SQLState: 23000
13-02@13:07:42 ERROR (JDBCExceptionReporter.java:72)     - Duplicate entry '3472-37-34-XHTML-Extensible Hypertext Markup Language' for key 1
13-02@13:07:42 ERROR (AbstractFlushingEventListener.java:301)     - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [org.fundacionctic.oa.model.InfoCompleja]
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2202)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2595)
   at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:388)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:363)
   at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:622)
   at org.fundacionctic.oa.dao.PersistenceDAOSpringHibernate.insertarInfoCompleja(PersistenceDAOSpringHibernate.java:63)
   at org.fundacionctic.oa.service.OAServiceImpl.onMessage(OAServiceImpl.java:223)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:203)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:162)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:209)
   at $Proxy15.onMessage(Unknown Source)
   at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:854)
   at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:793)
   at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:763)
   at org.springframework.jms.listener.DefaultMessageListenerContainer.doReceiveAndExecute(DefaultMessageListenerContainer.java:513)
   at org.springframework.jms.listener.DefaultMessageListenerContainer.receiveAndExecute(DefaultMessageListenerContainer.java:460)
   at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:871)
   at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:824)
   at org.springframework.core.task.SimpleAsyncTaskExecutor$ConcurrencyThrottlingRunnable.run(SimpleAsyncTaskExecutor.java:203)
   at java.lang.Thread.run(Thread.java:595)
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '3472-37-34-XHTML-Extensible Hypertext Markup Language' for key 1
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
   at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1169)
   at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:693)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1404)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1318)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1303)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
   at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2182)
   ... 33 more
13-02@13:07:42 INFO  (OAServiceImpl.java:244)     - ERROR DataIntegrityViolationException: en PAGINA '3472' al introducir la INCIDENCIA '37 - ' de la pagina: '/web/contenidos/es/accesibilidad.html' con info:'XHTML - Extensible Hypertext Markup Language' : could not insert: [org.fundacionctic.oa.model.InfoCompleja]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [org.fundacionctic.oa.model.InfoCompleja]




Name and version of the database you are using: MySql 5; SQLServer 8


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

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.