-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cannot find DataSource that has already configured in Tomcat
PostPosted: Tue Sep 27, 2005 4:28 am 
Newbie

Joined: Tue Sep 27, 2005 4:20 am
Posts: 6
Env
========
Tomcat 5.5.9
Hibernate 3.1

I',m having a problem of getting the DataSource that has already bound to the Tomcat JNDI.

I'm able to lookup the Datasource thru the InitialContext Look.
<b>
InitialContext ini = new javax.naming.InitialContext();
System.out.println( "Looking up DataSource" );

DataSource sc = ( DataSource ) ini.lookup( "java:comp/env/csvlite/connection" );</b>


But when i delegate it to Hibernate to lookup the DataSource from tomcat, I got the following Exception
<b>
org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:12
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:366)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1797)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1125)
at com.MyServlet.doPost(MyServlet.java:59)
at com.MyServlet.doGet(MyServlet.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: javax.naming.NameNotFoundException: Name sample is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:769)
at org.apache.naming.NamingContext.lookup(NamingContext.java:152)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)<b>


Below is the configuration data.

in Server.xml
=========
<Context path="/csvlite" docBase="csvlite"
debug="5" reloadable="true" crossContext="true">
<Resource name="sample/connection" auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost:1433;databaseName=csvlite;"
username="sa"
password="sample123"
maxActive="20"
maxIdle="30000"
maxWait="100" />

in web.xml
=======
<resource-ref>
<res-ref-name>sample/connection</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

The code that trying to create a session factory as below ( within servlet )
====================================
Configuration con = new Configuration();
SessionFactory factory = con.configure().buildSessionFactory();


Anyone could help me pls.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 5:51 am 
Beginner
Beginner

Joined: Fri Mar 19, 2004 7:21 am
Posts: 20
Hi,
You need to tell Hibernate the JNDI name of the datasource for the configuration to be able to hook things up.

hibernate.connection.datasource=java:comp/env/sample/connection
hibernate.dialect=org.hibernate.dialect.SybaseDialect

Damon.


Top
 Profile  
 
 Post subject: RE:
PostPosted: Sun Oct 09, 2005 9:22 pm 
Newbie

Joined: Tue Sep 27, 2005 4:20 am
Posts: 6
It finally works, thank you very much


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.