-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem integrating Hibernate with Tomcat...
PostPosted: Tue May 03, 2005 1:04 am 
Regular
Regular

Joined: Fri Feb 25, 2005 3:02 am
Posts: 71
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:3.0[/b]

[b]Mapping documents:
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- properties -->
<property name="connection.datasource">java:comp/env/jdbc/smsc</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>

<!-- mapping files -->
<mapping resource="com/gloptv/smsc/Customer.hbm.xml"/>
<mapping resource="com/gloptv/smsc/Parameter.hbm.xml"/>
<mapping resource="com/gloptv/smsc/User.hbm.xml"/>
<mapping resource="com/gloptv/smsc/Application.hbm.xml"/>
<mapping resource="com/gloptv/smsc/PhoneNumber.hbm.xml"/>
<mapping resource="com/gloptv/smsc/SmsOut.hbm.xml"/>
<mapping resource="com/gloptv/smsc/Operator.hbm.xml"/>
<mapping resource="com/gloptv/smsc/SmsIn.hbm.xml"/>
<mapping resource="com/gloptv/smsc/Synchro.hbm.xml"/>
<mapping resource="com/gloptv/smsc/Keyword.hbm.xml"/>
<mapping resource="com/gloptv/smsc/Status.hbm.xml"/>
</session-factory>
</hibernate-configuration>
[/b]

[b]Code between sessionFactory.openSession() and session.close():
try
{
System.out.println("11111");
session = HibernateUtil.currentSession();
System.out.println("22222");
try
{
tx = session.beginTransaction();
}
catch(HibernateException he)
{
he.printStackTrace();
}
System.out.println("33333");
Query query = session.createQuery("FROM User u where u.name = :name AND u.password = :password");
query.setParameter("name", new String(name));
query.setParameter("password", new String(computePasswordHash(password)));
user = (User)query.uniqueResult();

Date today = Calendar.getInstance().getTime();
if (user != null)
{
setName(user.getName());
setDescription(user.getDescription());
setPassword(user.getPassword());
setIsAdmin(user.isIsAdmin());
setLoginDate(user.getLoginDate());
setLockedDate(user.getLockedDate());
setLastIp(user.getLastIp());
setCustomers(user.getCustomers());
status = STATUS_VALID;
user.setLoginDate(today);
user.setLastIp(lastIp);
session.save(user);
}
else // No user found
status = STATUS_INVALID;
tx.commit();
}
catch (Exception e)
{
if (tx != null)
tx.rollback();
throw new Exception(e.getMessage());
}
finally
{
HibernateUtil.closeSession();
}
[/b]

[b]Full stack trace of any exception that occurs:
11111
22222
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:413)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:49)
at org.hibernate.transaction.JDBCTransactionFactory.beginTransaction(JDBCTransactionFactory.java:19)
at org.hibernate.jdbc.JDBCContext.beginTransaction(JDBCContext.java:204)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1014)
at com.gloptv.smsc.User.initLogin(Unknown Source)
at com.gloptv.smsc.User.<init>(Unknown Source)
at org.apache.jsp.authenticate_jsp._jspService(authenticate_jsp.java:66)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
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:118)
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.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:410)
... 41 more
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:243)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
... 44 more
33333
Cannot create JDBC driver of class '' for connect URL 'null'
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:243)
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:773)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:59)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:118)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1505)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1053)
at com.gloptv.smsc.HibernateUtil.<clinit>(Unknown Source)
at com.gloptv.smsc.User.initLogin(Unknown Source)
at com.gloptv.smsc.User.<init>(Unknown Source)
at org.apache.jsp.authenticate_jsp._jspService(authenticate_jsp.java:66)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
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:118)
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.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

[/b]


[b]Name and version of the database you are using: postgresql 8.0[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]

Hi, am trying to integrate hibernate in Tomcat. I've followed the guidelines on the following link: http://www.hibernate.org/hib_docs/v3/re ... start.html

But I got the above error in catalina log. Can anyone please help me solved this problem

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 11:02 am 
Newbie

Joined: Fri Jan 14, 2005 2:53 pm
Posts: 7
Quote:
Cannot create JDBC driver of class '' for connect URL 'null'


We ran into this problem. It's not Hibernate at all, but a Tomcat config problem. Tomcat is failing to pass the config parameters to the DataSource object when it creates it, so you get "" and 'null' instead of what you need.

The correct answer will depend on which version of Tomcat you are using. We are using 5.5.7, and this is what worked:

In <tomcat>\conf\server.xml, define your jdbc connection and give it a global name.
Code:
      <Resource name="jdbc/database"
                auth="Container"
                type="javax.sql.DataSource"
                driverClassName="oracle.jdbc.driver.OracleDriver"
                url="jdbc:oracle:thin:@<your database info here>"
                username="<user>"
                password="<password>"
                maxActive="20"
                maxIdle="10"
                maxWait="-1"
                removeAbandoned="true"
                logAbandoned="true"
         />



In <tomcat>\conf\Catalina\localhost\<APPNAME>.xml, create a link between the global name and a local name:
Code:
<ResourceLink global="jdbc/database" name="jdbc/database" type="javax.sql.DataSource"/>


Then, in your hibernate.cfg.xml, set the connection.datasource name to the local name, which is what you seem to have done already.

The Tomcat documentation is a bit vague on how to do this, but after much experimenting this is what we ended up with.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 04, 2005 12:47 am 
Regular
Regular

Joined: Fri Feb 25, 2005 3:02 am
Posts: 71
thank you very much for the reply


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 12:30 am 
Newbie

Joined: Wed Dec 15, 2004 3:00 am
Posts: 1
Hi, I am a little confused. Why not just set
Quote:
<Resource name="jdbc/database"
auth="Container"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@<your database info here>"
username="<user>"
password="<password>"
maxActive="20"
maxIdle="10"
maxWait="-1"
removeAbandoned="true"
logAbandoned="true"
/>

in <tomcat>\conf\Catalina\localhost\<APPNAME>.xml? Is there any advantage to set it in <tomcat>\conf\server.xml over <tomcat>\conf\Catalina\localhost\<APPNAME>.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 12:43 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 6:29 am
Posts: 24
Hi,

Is it necessary to use JNDI when using Hibernate with tomcat i am not using JNDI based datasource , i am also having some problems with session when confguring hibernate is mandatory to give both hibernate.cfg.xml and hibernate.properties , i am giving only hibernate.cfg.xml .

plz help


my hibernate.cfg.xml is given below.

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


<hibernate-configuration>
<session-factory>

<property name="connection.url">jdbc:mysql://localhost/pheonix?autoReconnect=true</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.pool_size">12</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>


<!-- Mapping files -->


<mapping resource="com/transversalnet/docmanager/category/category.hbm.xml"/>
<mapping resource="com/transversalnet/docmanager/category/categorymap.hbm.xml"/>
<mapping resource="com/transversalnet/docmanager/category/reviewer.hbm.xml"/>
<mapping resource="com/transversalnet/usersandgroups/svfatwvu.hbm.xml"/>
<mapping resource="com/transversalnet/docmanager/attribute/dmsattribute.hbm.xml"/>

<!-- <mapping resource="com/transversalnet/docmanager/permission/dm_permission.hbm.xml" /> -->

</session-factory>
</hibernate-configuration>














thankz in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 1:25 am 
Regular
Regular

Joined: Fri Feb 25, 2005 3:02 am
Posts: 71
You can either you jndi datasource or specify the jdbc url, driver as you did. both of them works. For the use of either hibernate.cfg.xml or hibernate.properties, only hibernate.cfg.xml is needed.

Hope this helps


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