-->
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.  [ 5 posts ] 
Author Message
 Post subject: I can establish a session but can't start a transaction.
PostPosted: Fri Jul 30, 2004 3:26 am 
Newbie

Joined: Fri Jul 30, 2004 2:53 am
Posts: 4
I followed the "Getting Started" at
http://www.hibernate.org/152.html

and the "Quickstart with Tomcat" at
http://www.hibernate.org/hib_docs/refer ... start.html

I'm trying to run the suggested code in an HttpServlet:
Code:
...
public void doGet( ...
    try {
       
      Session session = HibernateUtil.currentSession();
         
      Transaction tx2= session.beginTransaction();
      
      Cat princess = new Cat();
      princess.setName("Princess");
      princess.setSex('F');
      princess.setWeight(7.4f);
      
      session.save(princess);
      tx2.commit();
      
      HibernateUtil.closeSession();
                
    }   
    catch (HibernateException he)
    {
       out.println("HibernateException: " + he.getMessage());
       he.printStackTrace(out);
    }
    catch (NestableException ne)
    {
       out.println("NestableException: " + ne.getMessage());
       ne.printStackTrace(out);
    }
    catch (Exception e)
    {
       out.println("Exception: " + e.getMessage());
       e.printStackTrace(out);
    }
...
}
...


Everything compiled.

The line
Code:
Transaction tx2= session.beginTransaction();

causes an Exception with .getMessage() saying "null"

printStackTrace() gives:
Code:
java.lang.UnsupportedOperationException
   at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:161)
   at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:532)
   at net.sf.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:56)
   at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278)
   at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3302)
   at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3282)
   at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:40)
   at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
   at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2227)
   at HelloNotePals.doGet(HelloNotePals.java:77)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:419)
   at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
   at java.lang.Thread.run(Thread.java:534)


So it's not a HibernateException or a NestableException.

Any idea what the cause may be?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 30, 2004 1:23 pm 
Newbie

Joined: Tue Jun 29, 2004 12:18 pm
Posts: 5
Location: Anaheim, CA
I get that helpful little error message when working with something that doesn't support transactions. Make sure your JDBC Driver/DataSource is transaction-aware, your connection supports them (i.e. through a connection property), and that the table you are working against also supports transactions (on our DB -- an AS/400 -- transaction control must be explicitly enabled on a per-table basis).

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 10:12 pm 
Newbie

Joined: Fri Jul 30, 2004 2:53 am
Posts: 4
I'm using MySQL Connector/J 3.0.14-production as my JDBC driver.

My colleaque also tried my code with the same driver and database (MySQL).
It worked for him even though his table is using InnoDB (supposedly doesn't support transactions).

I am still getting the same exception error message.
What else could be causing it?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 11:10 am 
Newbie

Joined: Tue Jun 29, 2004 12:18 pm
Posts: 5
Location: Anaheim, CA
No, by default, MySQL is non-transactional, and InnoDB is one of MySQL's transactional storage engines. From the MySQL website: "InnoDB is a transaction-safe, ACID-compliant storage engine with commit, rollback, crash recovery and row-level locking capabilities." The MySQL manual has some more information on table types.

Eric


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 11:41 pm 
Newbie

Joined: Fri Jul 30, 2004 2:53 am
Posts: 4
I discovered the cause of the errors.

I had a copy of hibernate.properties in my quickstart/WEB-INF/classes/

The code worked once I removed that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.