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.
posted 12 years ago
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() ?
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads