- This topic has 1 reply, 2 voices, and was last updated 18 years ago by Riyad Kalla.
-
AuthorPosts
-
lilekhafMemberI am using Eclipse SDK, Hibernate 3, with Tomcat 5.5. I have a datasource setup, a hibernate config file, and I get the following error message when I try to do a simple Criteria query via Hibernate.
org.hibernate.exception.GenericJDBCException: Cannot open connection
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
org.hibernate.loader.Loader.doQuery(Loader.java:661)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:2211)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
org.hibernate.loader.Loader.list(Loader.java:2090)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
org.nipr.pdb.action.TestAction.doExecute(TestAction.java:41)
org.nipr.shared.action.BaseAction.execute(BaseAction.java:35)
org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:53)
org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:64)
org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:459)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)Here is my Context.xml in web/META-INF dir.
<?xml version=”1.0″ encoding=”UTF-8″?>
<Context path=”/PDB_CSR_REPORTS” reloadable=”true”
docBase=”C:\apache-tomcat-5.5.20\webapps\PDB_CSR_REPORTS”
workDir=”C:\apache-tomcat-5.5.20\webapps\PDB_CSR_REPORTS”><Resource name=”jdbc/PDBCSRdb” auth=”Container”
type=”javax.sql.DataSource”
maxActive=”100″ maxIdle=”30″ maxWait=”100″
username=”userid” password=”pswd”
driverClassName=”oracle.jdbc.driver.OracleDriver”
url=”jdbc:oracle:thin:@url:port:dbName?autoReconnect=true”/>
</Context>Here is my Hibernate.cfg.xml file in web/classes dir.
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hibernate-configuration PUBLIC
“-//Hibernate/Hibernate Configuration DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”><hibernate-configuration>
<session-factory name=”PDBCSRDBSessionFactory”>
<property name=”hibernate.transaction.factory_class”>org.hibernate.transaction.JDBCTransactionFactory</property>
<property name=”connection.datasource”>java:comp/env/jdbc/PDBCSRdb</property>
<property name=”show_sql”>true</property>
<property name=”dialect”>org.hibernate.dialect.Oracle9Dialect</property><mapping resource=”org/nipr/shared/dataaccess/config/CSRInputData.hbm.xml”/>
<mapping resource=”org/nipr/shared/dataaccess/config/QualificationDecode.hbm.xml”/>
</session-factory>
</hibernate-configuration>Here is the code that I call to get the Hibernate Session.
try {
Context ic = new InitialContext();
sessionFactory = (SessionFactory) ic.lookup(“PDBCSRDBSessionFactory”);
}
catch(NamingException e) {
logger.info(“Session factory isn’t initialized!”,null);
}
if (session == null) {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
}
catch(HibernateException e) {
logger.error(“Error in getting Hibernate Session.”,e);
e.printStackTrace();
System.out.println(“Message:”+e.getMessage());
}
}Here is the code I call to get the data, and the exception happens here.
DataAccess da = new DataAccess();
Session session = da.getHibernateSession();
Criteria criteria = session.createCriteria(QualificationDecode.class);
Collection list = (ArrayList)criteria.list();After the call criteria.list() nothing happens the exception occurs. Any ideas on what’s going on here or what I am going wrong here? I was able to connect to the db using the above url string, userid, pswd and same drive with simple jdbc connection. Thanks for helping!.
– Lakester
Riyad KallaMemberMoving to OT > Soft Dev
There may be more telling details farther down the exception chain… for example maybe something like “ClassNotFoundException” for your JDBC driver would suggest your paths aren’t setup correctly.
-
AuthorPosts