• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help!! error in session.beginTransaction()

 
Like Zhang
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic