-->
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.  [ 4 posts ] 
Author Message
 Post subject: using hibernate with webservices accessing through Tomcat
PostPosted: Thu Jun 16, 2005 7:32 pm 
Newbie

Joined: Thu Jun 16, 2005 7:24 pm
Posts: 6
Is there a way to access the JNDI configured through Tomcat and get the jdbc connection. Currently, I can use access Hibernate and run it successfully hitting Sybase database. But I need to run webservices and access the database through Hibernate. How would I do that?


Hibernate version: hibernate 3.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<property name="connection.datasource">java:comp/env/jdbc/lowes</property>
<property name="show_sql">false</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

<!-- Mapping files -->
<mapping resource="Cat.hbm.xml"/>

</session-factory>

</hibernate-configuration>


Full stack trace of any exception that occurs:
19:28:46,430 FATAL DatasourceConnectionProvider:47 - Could not find datasource: java:comp/env/jdbc/lowes"
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1004)
at com.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:55)
at com.hibernate.ProcessDB.main(ProcessDB.java:20)

Name and version of the database you are using: Sybase

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 9:41 pm 
Newbie

Joined: Sun Dec 19, 2004 8:10 pm
Posts: 10
Location: Australia
Do you map your lowes datasource in your server.xml file in your tomcat server? Can you post your server.xml.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 10:44 pm 
Beginner
Beginner

Joined: Mon Jun 13, 2005 5:52 pm
Posts: 43
Depends on the version of Tomcat.

Read this:

http://jakarta.apache.org/tomcat/tomcat ... howto.html

Specifically, look at steps 2 and 3 under "MySQL DBCP Example"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 10:56 am 
Newbie

Joined: Thu Jun 16, 2005 7:24 pm
Posts: 6
I have successfully ran Hibernate and access the database through servlet, running Tomcat.

What I wanted to do was debug a java acpplication through Eclipse thinking that Tomcat would load the jdbc on startup and through JNJDI, Hibernate would be able to access jdbc and database. But it is now clear that is not possible as far as I know.

But obviously, running web services, in whichever way, one goes through the app server anyway. So, Hibernate would be able to access the JDBC through JNDI. No reason to test it through java application.

Any opinion on this subject?

Thanks for having replied. Most appreciated.


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