-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Configuration using JDBC on TOMCAT 5.x
PostPosted: Mon Sep 12, 2005 10:50 am 
Newbie

Joined: Mon Sep 12, 2005 10:22 am
Posts: 1
Since it takes me 8 hours to get a hibernate project running on a Tomcat server due to problems with setting up the database i want to post here a working configuration.

Problem:
Hibernate3, datasource confiured as container managed JDBC, MYSQL database, always failed to connect to the database with the following error

Code:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context


Solution:
Only when adding a "java:comp/env/" in front of the jdbc name in the hibernate configuration, hibernate is able to connect.
e.g.:

Code:
<hibernate-configuration>

<session-factory>
  <property name="connection.datasource">java:comp/env/jdbc/engineDB</property>
   <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
[...]
</hibernate-configuration>


In the tomcat configuration file server.xml the according entry for the JDBC datatabase resource must be defined in the Server->Service->Engine->Host tag inside a context for the according web application:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Server>
[...]
  <GlobalNamingResources>
[...]
  </GlobalNamingResources>
  <Service name="Catalina">
[...]
    <Engine
        defaultHost="localhost"
        name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
      <Host appBase="webapps" name="localhost">
            <Context path="/engine_web" docBase="engine_web">
            <Resource name="jdbc/engineDB" auth="Container" scope="Shareable" type="javax.sql.DataSource"
            maxActive="100" maxIdle="30" maxWait="10000"
            username="root" password="*****" driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://192.168.0.8/engineDB?autoReconnect=true"/>
            </Context>
      </Host>
    </Engine>
  </Service>
</Server>



Finally the common/lib directory must contain the database driver.

Hopefully this is helpful for some of you ...


Top
 Profile  
 
 Post subject: Thank You
PostPosted: Thu Feb 02, 2006 5:26 pm 
Newbie

Joined: Thu Jun 09, 2005 4:13 pm
Posts: 7
Thank you so much for posting this. I have been searching all over for an example like this. Without this example I would not have been able to get Hibernate to connect to my database.

Thanks again!


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