• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help!! error in session.beginTransaction()

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use hibernate with struts.
First, the datasource is OK because I can use traditional method: initialize context and lookup.
However,when I use hibernate method, it throws:
net.sf.hibernate.exception.GenericJDBCException: Cannot open connection

I traced down and found the error happens when I execute session.beginTransaction()

My code is like this:

sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
System.out.println("session opened!"); //this can be printed out
transaction = session.beginTransaction();

Then after printing out "session opened", the exception is thrown.
Could anyone help me out? Thanks.
 
Like Zhang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked many examples on hibernate, there are some of my questions:

1. Do I have to add the following to server.xml in Tomcat?
<Context path="/quickstart" docBase="quickstart">
<Resource name="jdbc/quickstart" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/quickstart">
.......

I mean, I already have setup the datasource in Tomcat and it works fine without hibernate. I don't know if I need to add it again in the server.xml

2. When I create the sessionFactory, should I use any parameters or just use createFactory() ?

Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic