-->
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.  [ 10 posts ] 
Author Message
 Post subject: org.hibernate.HibernateException: Could not find datasource
PostPosted: Fri Sep 23, 2005 5:30 pm 
Newbie

Joined: Fri Sep 23, 2005 5:20 pm
Posts: 5
I am using the hibernate 3.0 with weblogic server 8.1 and oracle. I am getting the following exception, when I try to execute the program.

Created the data source and deployed on the server.

Here is the exception:

Process started
Attached successfully.
Test.java ....
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Could not find datasource
org.hibernate.HibernateException: Could not find datasource

at org.hibernate.connection.DatasourceConnectionProvider.configure(Ljava.util.Properties;)V(DatasourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Ljava.util.Properties;)Lorg.hibernate.connection.ConnectionProvider;(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(Ljava.util.Properties;)Lorg.hibernate.connection.ConnectionProvider;(SettingsFactory.java:362)
at org.hibernate.cfg.SettingsFactory.buildSettings(Ljava.util.Properties;)Lorg.hibernate.cfg.Settings;(SettingsFactory.java:60)
at org.hibernate.cfg.Configuration.buildSettings()Lorg.hibernate.cfg.Settings;(Configuration.java:1463)
at org.hibernate.cfg.Configuration.buildSessionFactory()Lorg.hibernate.SessionFactory;(Configuration.java:1004)
at Test.main([Ljava.lang.String;)V(Test.java:20)
Caused by: 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(Ljava.util.Hashtable;)Ljavax.naming.Context;(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx()Ljavax.naming.Context;(InitialContext.java:243)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Ljava.lang.String;)Ljavax.naming.Context;(InitialContext.java:280)
at javax.naming.InitialContext.lookup(Ljava.lang.String;)Ljava.lang.Object;(InitialContext.java:347)
at org.hibernate.connection.DatasourceConnectionProvider.configure(Ljava.util.Properties;)V(DatasourceConnectionProvider.java:44)
... 6 more
Could not find datasource
java.lang.NullPointerException
at Test.main([Ljava.lang.String;)V(Test.java:38)
at Test.main([Ljava.lang.String;)V(Test.java:35)
Debugging Finished


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 8:31 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
In a J2EE environment the JDBC connection should be available through a JNDI lookup. It seems that in your case you have missed configuring the JNDI factory. Read Weblogic related documentation.

./alex
--
.the_mindstorm.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 8:51 pm 
Newbie

Joined: Fri Sep 23, 2005 5:20 pm
Posts: 5
I found the solution through google search.

If anyone has this problem, add these 2 properties to the hibernate.cfg

<property name="jndi.url">t3://localhost:7001</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 9:09 pm 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
check page 29 of the Hibernate Reference Documentation ;-)

./alex
--
.the_mindstorm.


ps: don't forget to rate answers


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 1:19 pm 
Newbie

Joined: Fri Sep 23, 2005 5:20 pm
Posts: 5
Thanks for your reference.....The document says, atleast one property and also, the jndi.class and jndi.url are optional. But you should give these properties to make it work with application server without making any JNDI configuration in app server.

For use inside an application server, you should almost always configure Hibernate to obtain connections from an application server Datasource registered in JNDI. You'll need to set at least one of the following properties:Table 4.2. Hibernate Datasource Properties
Propery name Purpose
hibernate.connection.datasource datasource JNDI name
hibernate.jndi.url URL of the JNDI provider (optional)
hibernate.jndi.class class of the JNDI InitialContextFactory (optional)
hibernate.connection.username database user (optional)
hibernate.connection.password database user password (optional)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 12:40 am 
Newbie

Joined: Sun Oct 16, 2005 1:02 am
Posts: 3
I am new to hibernate and I am using hibernate3, weblogic8 and oracle9i. I am using all of the above properties but still I am getting the following error. Can you please share some thoughts on how you solved this.I also wrote a weblogic startup class as specified in the documentation. But unfortunately I couldn't find the Datasource class. Do we need to write a start up class for weblogic8 to make hibernate work?

Initially I was using Tomcat and things work perfectly alright.

Could not find datasource
org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(Ljava.util.Properties;)V(DatasourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(Ljava.util.Properties;)Lorg.hibernate.connection.ConnectionProvider;(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(Ljava.util.Properties;)Lorg.hibernate.connection.ConnectionProvider;(SettingsFactory.java:362)

Thanks in advance.

Sri


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 12:09 pm 
Newbie

Joined: Fri Sep 23, 2005 5:20 pm
Posts: 5
Do you have the following properties in your config file. If not, add the following properties and try.

<property name="jndi.url">t3://localhost:7001</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:01 pm 
Newbie

Joined: Sun Oct 16, 2005 1:02 am
Posts: 3
These are the properties I have set

<property name="show_sql">true</property>
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
<property name="connection.datasource">java:/prod</property>
<property name="jndi.url">t3://localhost:7001</property>
<property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<property name="connection.username"></property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>


And my hibernate Session Factory is :

public class HibernateSessionFactory {

/**
* Location of hibernate.cfg.xml file. NOTICE: Location should be on the
* classpath as Hibernate uses #resourceAsStream style lookup for its
* configuration file. That is place the config file in a Java package - the
* default location is the default Java package.<br>
* <br>
* Examples: <br>
* <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
* CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
*/
private static String CONFIG_FILE_LOCATION = "/com/gene/hibernate/xml/hibernate.cfg.xml";

/** Holds a single instance of Session */
private static final ThreadLocal threadLocal = new ThreadLocal();

/** The single instance of hibernate configuration */
private static final Configuration cfg = new Configuration();

/** The single instance of hibernate SessionFactory */
private static org.hibernate.SessionFactory sessionFactory;

/**
* Returns the ThreadLocal Session instance. Lazy initialize the
* <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session currentSession() throws HibernateException {


Session session = (Session) threadLocal.get();

if (session != null && !session.isOpen())
session = null;
if (session == null) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}

return session;
}

/**
* Close the single hibernate session instance.
*
* @throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);

if (session != null) {
session.close();
}
}

/**
* Default constructor.
*/
private HibernateSessionFactory() {
}

}



Do I need to write a start up class for weblogic?

Thanks
sri


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 4:59 pm 
Newbie

Joined: Fri Sep 23, 2005 5:20 pm
Posts: 5
Give the datasource name as "prod" ,actual datasource name. Dont add any prefix/suffix.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 10:27 pm 
Newbie

Joined: Sun Oct 16, 2005 1:02 am
Posts: 3
Thanks a lot.This helped me.


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