Question : [Servlet Error]-[LocalTransaction rolled-back due to setRollbackOnly]: com.ibm.ws.LocalTransactio<wbr />n.Rolledba<wbr />ckExceptio<wbr />n

Hi,
I have configured oracle datasource in WSAD5.1, i am trying to write to database using hibernate framework from a web application. i have copied all the required jar files into WEB-INF/lib folder, and created hibernate.cfg.xml, Person.hbm.xml ,and a TestServlet.java, following is the code listing for each file

hibernate.cfg.xml:

http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


      
            jdbc/OraDS
      

      
            org.hibernate.dialect.Oracle9Dialect
      

      



Person.hbm.xml

"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>
      
            
                  
            

      
      
      
      



TestServlet.java
package com.siva.seminar.web.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.siva.seminar.hibernate.Person;


public class TestServlet extends HttpServlet {
      public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
            
            DataSource ds = null;
            InitialContext ctx = null;
            res.setContentType("text/html");
            PrintWriter out = res.getWriter();
            
            
            try {
                  Configuration cfg = new Configuration();
                  SessionFactory factory = cfg.configure().buildSessionFactory();
                  Person person = new Person();
                  person.setAddress("2418 Independence");
                  person.setFirstName("Siva");
                  person.setLastName("Madala");
                  Session session = factory.openSession();
                  session.save(person);
                  session.flush();
                  out.print("success");
            }
            catch(Exception ex){
                  ex.printStackTrace();
                  out.print("Failure");
            }
            
      
            
      }
}


after running the server, when i hit the servlet following exception is thrown:

[2/26/06 9:51:05:703 CST] 4288e104 WebGroup      E SRVE0026E: [Servlet Error]-[LocalTransaction rolled-back due to setRollbackOnly]: com.ibm.ws.LocalTransaction.RolledbackException
      at com.ibm.ws.LocalTransaction.LocalTranCoordImpl.cleanup(LocalTranCoordImpl.java:1073)
      at com.ibm.ws.webcontainer.webapp.WebAppTransactionCollaborator.postInvoke(WebAppTransactionCollaborator.java:249)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:708)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
      at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
      at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
      at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
      at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:116)
      at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
      at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
      at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
      at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
      at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)


=Thanks for your help!!

Answer : [Servlet Error]-[LocalTransaction rolled-back due to setRollbackOnly]: com.ibm.ws.LocalTransactio<wbr />n.Rolledba<wbr />ckExceptio<wbr />n

Hi,

Look in the web.xml editor, servlets tab, lower right (all the way down).  Look for websphere extensions.  You could change "unresolved action" to commit ... that would cleanup without rollback.  I don't think this message is actually an error.  I saw it in one of my applications but everything was working fine.

I faced this problem recently. As I understand, the issue is that the TransactionManager is either not XA compliant or XA aware.
When I change the TransactionManager to use JtaTransactionManager, the error vanished.

look here for more help..
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=46&t=005300

Hope this helps.

R.K
Random Solutions  
 
programming4us programming4us