Hello.
I have a stateless session bean, entity bean, servlet program.
When SQL exception happens, the rollback cannot be done though the method of 
the session bean is called from the servlet. 
When the Runtime Exception is compulsorily generated in the session bean, the 
roll backing is done. 
However, the following exceptions are thrown out for an actual SQL exception, 
and the roll backing is not done.
How should I do to do the roll backing?
May I have advice?


Servlet Class: 

  |     public Value doBiz(Hashtable param, HttpServletRequest req){
  |             String  page = "/jsp/test/TestEntryEnd.jsp";
  |             Value value = new Value();
  |             
  |             try{
  |                     TestUserBean usrs = new TestUserBean();
  |                     usrs.setTestUserId(1);
  |                     usrs.setTestName("test name");
  |                     
  |                     /* DB insert */
  |                     TestService service = new TestService();
  |                     service.insertTestUser(usrs);
  |                     
  |                     /* To cause the exception, the data of same ID is 
inserted again. */
  |                     TestUserBean usrs2 = new TestUserBean();
  |                     usrs2.setTestUserId(1);
  |                     usrs2.setTestName("test name2");
  |                     
  |                     service.insertTestUser(usrs2);
  |                     
  |                     value.setForwardPage(page);
  |             }catch(Exception ex){
  |                     System.out.println("***** TestEntryEnd.doBiz catch ex = 
" + ex);
  |                     value.addErrorMessage("TestEntryEnd Error");
  |                     value.setError(true);
  |             }
  |             return value;
  |     }
  | 





Stateless Session Bean Class: 

  | @Stateless
  | @Local(TestSession.class)
  | @Remote(TestSession.class)
  | 
  | public class TestSessionBean  implements TestSession{
  |     @PersistenceContext
  |     protected  EntityManager em;
  |     
  |     @TransactionAttribute(TransactionAttributeType.REQUIRED)
  |     public void insertTestUser(TestUserBean usrs){
  |             em.persist(usrs);
  |             
  |             /* When the exception is compulsorily caused here, the roll 
backing is done. */
  |             //throw new RuntimeException("!! RuntimeException !?");
  |     }
  | }
  | 


Error stack trace
11:33:30,354 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
11:33:30,355 ERROR [JDBCExceptionReporter] Batch entry 0 insert into testuser 
(testName, testUserId) values (7, 7) was aborted.  Call getNextException to see 
the cause.
11:33:30,355 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: 23505
11:33:30,355 ERROR [JDBCExceptionReporter] ERROR: duplicate key violates unique 
constraint "testuser_pkey"
11:33:30,356 ERROR [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:69)
        at 
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at 
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
        at 
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:91)
        at 
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
        at 
org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:171)
        at 
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2048)
        at 
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
        at 
org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
        at 
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
        at 
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
        at 
org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:59)
        at 
org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1473)
        at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1092)
        at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:306)
        at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
        at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
        at 
org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
        at 
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
        at 
org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
        at 
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
        at 
org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
        at 
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
        at 
org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
        at 
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
        at 
org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
        at 
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
        at 
org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
        at 
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
        at 
org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:178)
        at 
org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:74)
        at $Proxy115.insertTestUser(Unknown Source)
        at TestService.insertTestUser(TestService.java:29)
        at TestEntryEnd.doBiz(TestEntryEnd.java:71)
        at TestServlet.service(TestServlet.java:95)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at 
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at 
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at 
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at 
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at 
org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into testuser 
(testName, testUserId) values (7, 7) was aborted.  Call getNextException to see 
the cause.
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2497)
        at 
org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:399)
        at 
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1298)
        at 
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:347)
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2559)
        at 
org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:487)
        at 
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
        at 
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
        ... 57 more


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3950034#3950034

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3950034


_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to