-->
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: Problem with JNDI context in Tomcat and Hibernate
PostPosted: Sun Aug 29, 2004 6:05 am 
Newbie

Joined: Thu Aug 26, 2004 4:32 am
Posts: 2
Hibernate version:2.1

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

<session-factory name="java:hibernate/HibernateFactory">

<property name="connection.datasource">java:hibernate/HibernateFactory</property>
<property name="show_sql">true</property>



<!-- Settings for a remote MySQL database. -->
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">mysql://localhost/oozlooz</property>
<property name="connection.username">oozlooz</property>
<property name="connection.password">Jerich0</property>

<!-- Use the C3P0 connection pool. -->
<property name="c3p0.min_size">3</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.timeout">1800</property>

<!-- Use EHCache but not the query cache. -->
<property name="cache.provider_class">net.sf.ehcache.hibernate.Provider</property>
<property name="cache.use_query_cache">false</property>
<property name="cache.use_minimal_puts">false</property>

<mapping resource="oozlooz/dataobjects/persistence/user.hbm.xml"/>

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


Code between sessionFactory.openSession() and session.close(): //Hibernate session
Session sess =HibernateUtil.currentSession();
Transaction tx=sess.beginTransaction();
try{
//Get the user class object referring to the table "user"
user uObj = new user();
//Create the query
Query query=sess.createQuery("INSERT INTO USER VALUES(:username,:joindate ,:imageURL, :password)");
query.setString("username",username);
query.setDate("joindate",sqlNow);
query.setString("imageURL",imageURL);
query.setString("password",password);
//Save this record
sess.save(uObj);

}catch(Exception e){
e.printStackTrace();
tx.rollback();
}finally{
tx.commit();
HibernateUtil.closeSession();
}


Full stack trace of any exception that occurs:net.sf.hibernate.HibernateException: Could not find datasource
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48)
at net.sf.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:83)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:65)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1155)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
at oozlooz.dataobjects.HibernateUtil.<clinit>(HibernateUtil.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:306)
at java.lang.Class.newInstance(Class.java:259)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:977)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:862)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3991)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4335)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
at org.apache.catalina.core.StandardService.start(StandardService.java:476)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:2298)
at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:284)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:422)
Caused by: javax.naming.NameNotFoundException: Name hibernate is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:768)
at org.apache.naming.NamingContext.lookup(NamingContext.java:151)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at net.sf.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
... 28 more


Name and version of the database you are using:mysql 4

Debug level Hibernate log excerpt:

I am using exactly the same code given in the Hibernate tutorials with Tomcat5, only difference is that I dont want to use DBCP connection pool but C3PO connection pool, I cant find relevent documents anywhere. Please help !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 1:12 pm 
Newbie

Joined: Thu Sep 09, 2004 1:05 pm
Posts: 4
Hi,


Log on the administration interface of Tomcat and make sure the global data source has been created.

Then expand the Services (Cataline) / Host (localhost) branches and expand your context.

There create a ressource link to the global data source (They can both have the same name).

Or optionally, create the data source directly there, but it won't be available to any other context.

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.  [ 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.