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: org.hibernate.HibernateException: Could not find datasource
PostPosted: Wed Jul 26, 2006 5:54 am 
Newbie

Joined: Tue Jul 25, 2006 7:51 am
Posts: 1
Hi, I am getting the following problem.

org.hibernate.HibernateException: Could not find datasource , And its occuring at

sessionFactory = new Configuration().configure().buildSessionFactory(); in static block of HibernateUtil.java.


I am using Tomcat 5.0 and int conf\server.xml i have added the follwoing.

<Context path="/quickstart" docBase="quickstart">

<Resource name="jdbc/quickstart" scope="Shareable" type="javax.sql.DataSource"/>

<ResourceParams name="jdbc/quickstart">

<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>

<!-- DBCP database connection settings -->

<parameter>
<name>url</name>
<value>jdbc:postgresql://localhost/quickstart</value>
</parameter>

<parameter>
<name>driverClassName</name><value>org.postgresql.Driver</value>
</parameter>

<parameter>
<name>username</name>
<value>quickstart</value>
</parameter>

<parameter>
<name>password</name>
<value>secret</value>
</parameter>

<!-- DBCP connection pooling options -->

<parameter>
<name>maxWait</name>
<value>3000</value>
</parameter>

<parameter>
<name>maxIdle</name>
<value>100</value>
</parameter>

<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>

</ResourceParams>

</Context>

I placed hibernate.cfg.xml file in WEB-INF\classes and its contains the follwing configuration.

<?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/quickstart</property>

<property name="show_sql">false</property>

<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>

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

</hibernate-configuration>

I am using oracle9i database.

My HibernateUtil.java file is as follows.

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.out.println(ex);
throw new ExceptionInInitializerError(ex);
}
}
public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() {

Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}

public static void closeSession() {
Session s = (Session) session.get();
if (s != null)
s.close();
session.set(null);
}

}

I wrote a servlet which will store Cat object into db.

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.hibernate.examples.quickstart.Cat;
import org.hibernate.*;

public class FirstHibernate extends HttpServlet
{
public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
{


Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Cat princess = new Cat();
princess.setName("Princess");
princess.setSex('F');
princess.setWeight(7.4f);
session.save(princess);
tx.commit();
HibernateUtil.closeSession();
System.out.println("Hello");

}

}


Please let me know the mistake i have done.

_________________
Rakesh Buddha


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 26, 2006 3:26 pm 
Beginner
Beginner

Joined: Tue Sep 27, 2005 2:51 pm
Posts: 27
look at
http://forums.hibernate.org/viewtopic.php?t=961880&highlight=datasource&sid=07da1f0fbba279b202b227a394da8258

It may solve your problem

_________________
Dave Ziebol


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.