-->
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.  [ 12 posts ] 
Author Message
 Post subject: stuck with datasource not found error
PostPosted: Sat Jun 11, 2005 12:19 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
i'm stuck with this problem of datasource not found. i'm running the example in hibernate quickstart with tomcat. the one with Cat.hbm.xml.
i'm trying to use a jdbc driver (j connector) for a mysql 4.1.10a-nt database, and configuring tomcat to see the db as a datasource.



Hibernate version:
3.0
Mapping documents:

hibernate.cfg.xml, put in WEB-INF/classes directory of my app
Code:
<?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>
        <!-- net.sf.hibernate.connection.DatasourceConnectionProvider -->
        <property name="connection.datasource">jdbc/quickstart</property>       
       
        <property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
               
                <property name="show_sql">false</property>
               
                <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
                <property name="connection.provider_class">com.mysql.jdbc.Driver</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
                <property name="connection.username">root</property> 
                <property name="connection.password">******</property>
   <!-- Mapping files -->
   <mapping resource="net/sf/hibernate/examples/quickstart/Cat.hbm.xml"/>
   </session-factory>
</hibernate-configuration>





server.xml of tomcat, only the section <Context> added befor the end of </Host>:
Code:

<Context path="/quickstart" docBase="quickstart" debug="5" reloadable="true" crossContext="true">
            <Logger className="org.apache.catalina.logger.FileLogger"
                    prefix="localhost_DBTest_log." suffix=".txt"
             timestamp="true"/>
           
           
       <Resource name="jdbc/quickstart" auth="Container" 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:mysql://localhost:3306/quickstart?relaxAutoCommit=true</value>
          </parameter>
      
          <parameter>
             <name>driverClassName</name><value>com.mysql.jdbc.Driver</value>
          </parameter>
      
          <parameter>
             <name>username</name>
             <value>root</value>
          </parameter>
      
          <parameter>
             <name>password</name>
             <value>******</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>






Code between sessionFactory.openSession() and session.close():
i am trying to use the simple code suggested in the example, called HibernateUtil.java and i added a main() to test the app:
i am copying only the code with problems, in fact the error i get is on this line:

throw new ExceptionInInitializerError(ex);

Code:

(.......)
   

        try {
        // Create the SessionFactory
           
           
        sessionFactory = new Configuration().configure().buildSessionFactory();
       
       
       
        } catch (Throwable ex) {
                log.error("Initial SessionFactory creation failed.", ex);
                throw new ExceptionInInitializerError(ex);
           

(.....)
   
   
    public static void main(String[] args) {
       
        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();

    }

}








Full stack trace of any exception that occurs:
in bold the datasource problem:


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
java.lang.ExceptionInInitializerError
at HibernateUtil.<clinit>(HibernateUtil.java:37)
Caused by: org.hibernate.HibernateException: Could not find datasource
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:349)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:58)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1509)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1054)
at HibernateUtil.<clinit>(HibernateUtil.java:31)
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(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:44)
... 6 more
Exception in thread "main"
Java Result: 1


Name and version of the database you are using:

mysql 4.1.10a-nt

The generated SQL (show_sql=true):
i don't think sql is yet generated


Debug level Hibernate log excerpt:
don't know how to find hibernate debug log, tell me if you do


maybe it doesn't find the hibernate.cfg.xml? do i have to put it in a different directory or in the classpath? i am not using hibernate.properties, is that a mistake? i don't think, since i'm using hibernate.cfg.xml.


Top
 Profile  
 
 Post subject: Re: stuck with datasource not found error
PostPosted: Sat Jun 11, 2005 3:15 pm 
Newbie

Joined: Mon Oct 18, 2004 7:59 am
Posts: 10
Location: Netherlands
This may not be it, but you are using Hibernate 3.0, and there is no net.sf.hibernate.transaction.JDBCTransactionFactory class there. Since Hibernate 3 stuff is migrated to org.hibernate.*


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 11, 2005 5:03 pm 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
One more (not sure): I think there is a difference between connection.driver_class (which is correct imo) and connection.provider_class (which is supposed to be used with custom jdbc connection providers). You can find all you need about this in the free documentation - chapter 4.

:alex |.::the_mindstorm::.|


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 11, 2005 8:55 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
thanx to both you guys now it's late tomorrow i'll try to mess with those things you said.
the problem is that every example on the quick start with tomcat are with 2.x hibernate version, and i still haven't found a place to look all the differences.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 12, 2005 5:51 am 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
i'm quite confused when talking about connection providers:
i am using a driver to connect to the mysqldb (connector/J is the driver), and it loads through the property
Code:
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

in hibernate.cfg.xml.
what do i have to put in
Code:
<property name="connection.provider_class">com.mysql.jdbc.Driver</property>
?
the same driver? it acts as a connection pooler or is it tomcat to do that work (since i configured a datasource in tomcat, the connection pooling should be its business).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 12, 2005 6:22 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
mox i strongly suggest you to read carrefully the Chapter 1 and Chapter 4. Those are explaining all you need to do in order to have Hibernate working.

:alex |.::the_mindstorm::.|


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 7:35 am 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
the first chapter at [url]file:///c:/Documents%20and%20Settings/matteo/Desktop/hibernate/HIBERNATE%20-%20Relational%20Persistence%20for%20Idiomatic%20Java.htm#quickstart[/url]
was very useful, it is updated to hibernate 3.0.3 and i was able to make my app work for a while (anyway there was a different error, but now i changed something and it says could not find datasource again...)[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 10:03 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
he he... and who do you think is the `mediumĀ“ here to identify the problem?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 10:03 am 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
i followed the hibernate reference documentation where it is explained the mapping of a Cat in tomcat, but somehow at runtime there's this error:

Code:


log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
java.lang.ExceptionInInitializerError
    at org.hibernate.examples.quickstart.HibernateUtil.<clinit>(HibernateUtil.java:32)
Caused by: org.hibernate.MappingException: Resource: Cat.hbm.xml not found
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1313)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1285)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1267)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1234)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1148)
    at org.hibernate.examples.quickstart.HibernateUtil.<clinit>(HibernateUtil.java:28)
Exception in thread "main"
Java Result: 1





i have Cat.hbm.xml in the same directory as Cat.java, and here i post the hibernate.cfg.xml and Cat.hbm.xml:



Code:

<?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.MySQLSQLDialect</property>

        <!-- Mapping files -->
        <mapping resource="org/hibernate/examples/quickstart/Cat.hbm.xml"/>

    </session-factory>

</hibernate-configuration>




the mapping resource is correct, since the string should include the packages hierarchy.


Code:


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

    <class name="org.hibernate.examples.quickstart.Cat" table="CAT">

        <!-- A 32 hex character is our surrogate key. It's automatically
            generated by Hibernate with the UUID pattern. -->
        <id name="id" type="string" unsaved-value="null" >
            <column name="CAT_ID" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>

        <!-- A cat has to have a name, but it shouldn' be too long. -->
        <property name="name">
            <column name="NAME" length="16" not-null="true"/>
        </property>

        <property name="sex"/>

        <property name="weight"/>

    </class>

</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 10:05 am 
Regular
Regular

Joined: Mon Apr 25, 2005 9:22 am
Posts: 62
Location: Bucharest/Romania
Is the hbm.xml file available in the classpath? (in the package org.hibernate.examples.quickstart)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 10:16 am 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
i post my line of classpath:

Code:

%JAVA_HOME%\lib;%JAVA_HOME%\mysql-connector-java-3.1.8-bin.jar;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\rt.jar;%CLASSPATH%;%JRE_HOME%\bin;C:\Programmi\hibernate-3.0\lib\hsqldb.jar;%HIBERNATE_HOME%;C:\Programmi\netbeans-4.0\nb4.0\jakarta-tomcat-5.0.28\webapps\quickstart2\src;.



Cat.hbm.xml resides in C:\Programmi\netbeans-4.0\nb4.0\jakarta-tomcat-5.0.28\webapps\quickstart2\src\org\hibernate\examples\quickstart\Cat.hbm.xml

and even if i add an entry with the path to this file
(C:\Programmi\netbeans-4.0\nb4.0\jakarta-tomcat-5.0.28\webapps\quickstart2\src\org\hibernate\examples\quickstart)
i still get that error.
it should be great if you could post me your classpath or tell me exactly what is mandatory to have in the classpath.
thanx again!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 9:48 am 
Beginner
Beginner

Joined: Tue May 17, 2005 7:39 am
Posts: 27
Location: Rome, Italy
i'm still here with the same stupid error about datasource, and the last chanche is to check the directory tree:
[url=http://www.pegasuseventi.com/vecchio_sito/secret/mox/directory_tree.jpg]
directory screenshot
[/url]
to see if it is correct. i'll be grateful anyone posting a windows classpath or something to help with the datasource.
double checking everything on the tomcat quickstart didn't work. i'll start it over from scratch.


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