-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: /hibernate.cfg.xml not found
PostPosted: Wed Nov 26, 2003 7:12 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi!

I have this puzzling problem:
Despite I put the /hibernate.cfg.xml in every possible (and unpossible) directory/classpath etc the application complians about not finding it.
Anyone recognize this irritating problem?

Excerpt from the last desperate attempt to get Hibernate to find it:
"net.sf.hibernate.HibernateException: /cainfo/hibernate.cfg.xml not found
at net.sf.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:708)
at net.sf.hibernate.cfg.Configuration.configure(Configuration.java:731)
at ks.rah.cainfo.HibernateSession.currentSession(Unknown Source)
at ks.rah.cainfo.persistence.ContactPeer.newContactTest(Unknown Source)
at ks.rah.cainfo.ShowInputFormHandler.handle(Unknown Source)" etc blablabla


Regards,

/Froberg


Top
 Profile  
 
 Post subject: The hibernate.cfg.xml
PostPosted: Wed Nov 26, 2003 7:52 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
This is the .cfg.xml by the way:

-----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/toktest</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<property name="connection.pool_size">10</property>
<property name="statement_cache.size">25</property>

<mapping resource="ks.rah.cainfo.bean.User"/>
<mapping resource="ks.rah.cainfo.bean.Contact"/>
<mapping resource="ks.rah.cainfo.bean.ContactType"/>
<mapping resource="ks.rah.cainfo.bean.ContactEntry"/>
<mapping resource="ks.rah.cainfo.bean.Option"/>
<mapping resource="ks.rah.cainfo.bean.Variable"/>
</session-factory>
</hibernate-configuration>
---------------------------------------------------------


Top
 Profile  
 
 Post subject: Every solution breeds new problems
PostPosted: Wed Nov 26, 2003 8:13 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
OK... now it seems to work, strangely enough with the following code:

sessionFactory = new Configuration().configure(new URL("/cainfo/hibernate.cfg.xml")).buildSessionFactory();

So it seems to load the .xml

but....

------------------------------------------------------------------
With the following code;

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import java.net.URL;

public class HibernateSession {

private static SessionFactory sessionFactory;
public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession()
throws HibernateException {
System.out.println ("1");
Session s = (Session) session.get();
System.out.println ("2");
if (s == null) {
System.out.println ("3");
// Don't get from JNDI, use a static SessionFactory
if (sessionFactory == null) {
try{
System.out.println ("4");
// Use default hibernate.cfg.xml
sessionFactory = new Configuration().configure(new URL("/cainfo/hibernate.cfg.xml")).buildSessionFactory();
}
catch(Exception ex)
{
System.out.println ("5");
}
}//if
System.out.println ("6");
s = sessionFactory.openSession();
System.out.println ("7");
session.set(s);
System.out.println ("8");
}//if
return s;
}



public static void closeSession()
throws HibernateException {

Session s = (Session) session.get();
session.set(null);
if (s != null) s.close();
}
}

taken from the Hibernate WIKI, the application throws a NullPointerException at line
" s = sessionFactory.openSession();"
I take it it must be the sessionFactory that is not created properly.

I also changed my hibernate.cfg.xml file to:

<hibernate-configuration>
<session-factory>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/toktest</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<property name="connection.pool_size">10</property>
<property name="statement_cache.size">25</property>

<mapping resource="ks/rah/cainfo/bean/User.hbm.xml"/>
<mapping resource="ks/rah/cainfo/bean/Contact.hbm.xml"/>
<mapping resource="ks/rah/cainfo/bean/ContactType.hbm.xml"/>
<mapping resource="ks/rah/cainfo/bean/ContactEntry.hbm.xml"/>
<mapping resource="ks/rah/cainfo/bean/Option.hbm.xml"/>
<mapping resource="ks/rah/cainfo/bean/Variable.hbm.xml"/>
</session-factory>
</hibernate-configuration>

I'm stuck!

Thanks in advance!

/Froberg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 8:47 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
So, check the log for the SessionFactory creation process and look up whats wrong. Increase the log level if it isn't giving you a good explanation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Log
PostPosted: Wed Nov 26, 2003 9:54 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Ok, thanks.

Where can I find that log?

/Froberg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 9:56 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate uses commons-logging, which in turn either uses Log4j if available or JDK1.4 logging. I can't tell you where the logs are in your environment.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 9:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Hibernate comes with a sample log4j.properties file as most people still use log4j as the primary logging library. This defines the logging levels and what gets logged. This file needs to be added to your classpath (and modified as necessary). [I am assuming a simple environment, otherwise you will have to look at your execution containers logging mechanism/configuration].


Top
 Profile  
 
 Post subject: Logs
PostPosted: Wed Nov 26, 2003 10:27 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
OK, Thanks.

I'm working with a Tomcat servlet app. I'm sorry to say that the approach with the log4j-configuration file and the .jar in the classpath throws about 150 exceptions. It's all about missig contructors and stuff. I don't seem to have any luck today.


Top
 Profile  
 
 Post subject: Am I stupid?
PostPosted: Wed Nov 26, 2003 11:18 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Sorry folks but I'm having a hard time accepting this.

Quote from http://jakarta.apache.org/log4j/docs/manual.html:

"The default log4j initialization is particularly useful in web-server environments. Under Tomcat 3.x and 4.x, you should place the log4j.properties under the WEB-INF/classes directory of your web-applications. Log4j will find the properties file and initialize itself. This is easy to do and it works."

Well.....

I have the log4j.properties file under WEB-INF/classes and the log4j.jar in the WEB-INF/lib of my web-app.

and still I get these exceptions....

----------------
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@1d686c1 for org.apache.commons.logging.impl.Log4JLogger
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:532)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:272)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:246)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:395)
at net.sf.hibernate.cfg.Configuration.<clinit>(Configuration.java:86)
... 38 more
Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log constructor [Ljava.lang.Class;@1d686c1 for org.apache.commons.logging.impl.Log4JLogger
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:432)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:525)
... 42 more
Caused by: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:1610)
at java.lang.Class.getConstructor0(Class.java:1922)
at java.lang.Class.getConstructor(Class.java:1019)
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:429)
... 43 more
-------------------------------------------

I'm happy it doesn't list them all. Maybe I should have stayed in church playing the organ, 'cause I don't get this tune... :-(((

/Froberg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 11:31 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The Jakarta Tomcat classloader and the autodetection of Jakarta commons-logging don't like each other sometimes. I recommend you get a fresh Tomcat, unpack it, create a new webapp context, throw in WEB-INF/lib/

- log4j.jar
- commons-logging*.jar

and a log4j.properties in WEB-INF/classes. Don't mess with anything in common/* or any other global Tomcat directory, or you will be in classloader hell. Try to deploy a simple Servlet in your webapp like this:

public class TestServlet extends HttpServlet {

private static final Log log = LogFactory.getLog(TestServlet.class);

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException {

log.info("GET method called.");

}

}

and check the catalina.out logfile in Tomcat/log/. Play with the log4j.properties until you are familiar with the basics.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: New day, same shit
PostPosted: Thu Nov 27, 2003 6:24 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi, thanks for advices!

Tried clean installation of Tomcat 4.1.27. Copied the minimal required jars to CATALINA_HOME/common/lib, that is:

dom4j.jar
cglib-asm.jar
commons-beanutils.jar
commons-collections.jar was already in the dir
commons-lang.jar
commons-logging.jar
commons-logging-api.jar already in directory
odmg.jar

Copied log4j-1.2.8.jar to <myapp>/WEB-INF/lib and log4j.properties to <myapp>/WEB-INF/classes

On execution log4j complained about missing Digester. Copied commons-digester to <myapp>/WEB-INF/lib. Still log4j throws a bunch of exceptions.

Copied commons-logging.jar to <myapp>/WEB-INF/lib
Now I get a most puzzling exception
--------------------
....
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Log4JLogger does not implement Log
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:532)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:272)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:246)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:395)
at net.sf.hibernate.cfg.Configuration.(Configuration.java:86)
... 36 more
Caused by: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Log4JLogger does not implement Log
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:416)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:525)
... 40 more
Caused by: org.apache.commons.logging.LogConfigurationException: Class org.apache.commons.logging.impl.Log4JLogger does not implement Log
at org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:412)
... 41 more

--------------------------
Log4jLogger does not implement Log!????
OK.....

I think I'm giving up on the log4j-stuff, it does not just seems to work the way it should.

Again, thanks for replies from all you guys!

Sincerely,

/Froberg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 7:26 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Welcome to Jakarta Hell. Again, you should not copy anything into TOMCAT/common/lib, only your JDBC driver if you'd like to use Tomcat connection pooling trhough JNDI.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Dantes Inferno
PostPosted: Thu Nov 27, 2003 7:53 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Report from the Seventh Circle of Classloader Hell! *lol*

I have to copy at least the jars that make Hibernate run, haven't I? I mean, all this fuzz is about making Hibernate work as expected. Are there an alternative way of letting Tomcat know about Hibernate jars except putting these int CATALINA_HOME/common/lib? Should I put them in JAVA_HOME/lib/ext instead?

I'm thinking about the fact that nothing works when I try to use a hibernate.cfg.xml version of property file.... could it be something about conflicting XML-readers??

I've tried this (rather clumsy and not so portable and very non-object-oriented) way of aquiring a hibernate.properties file and storing a SessionFactory in a Singleton...

--------------------------
private static final String APPBASE = "C:/jdk/tomcat-4.1.27/webapps/cainfo";
private static SessionFactory sessionFactory;
public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession()
throws HibernateException {
System.out.println ("1");
Session s = (Session) session.get();
System.out.println ("2");
if (s == null) {
System.out.println ("3");
// Don't get from JNDI, use a static SessionFactory
if (sessionFactory == null) {
try{
System.out.println ("4");
// Use default hibernate.cfg.xml
//sessionFactory = new Configuration().configure(new URL("/cainfo/hibernate.cfg.xml")).buildSessionFactory();

Properties props = new Properties();
props.load(new FileInputStream(APPBASE + "/hibernate.properties"));
sessionFactory = new Configuration().
addClass(ks.rah.cainfo.bean.User.class).
addClass(ks.rah.cainfo.bean.Contact.class).
addClass(ks.rah.cainfo.bean.ContactEntry.class).
addClass(ks.rah.cainfo.bean.ContactType.class).
addClass(ks.rah.cainfo.bean.Option.class).
addClass(ks.rah.cainfo.bean.Variable.class).
setProperties(props).
buildSessionFactory();


}
catch(Exception ex)
{
System.out.println ("5");
}
}//if
System.out.println ("6");
s = sessionFactory.openSession();
System.out.println ("7");
session.set(s);
System.out.println ("8");
}//if
return s;
}
----------------------
It works as a clock, and it makes it even more puzzling that the *.cfg.xml way just won't work.....
And hardcoding the path to the property file.... well, I'm glad my Java-professor doesn't know this...

/Froberg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 8:24 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You should not copy them in any global classpath directory in Tomcat. Please, read the Quickstart again. Copy them into your webapp WEB-INF/lib directory. The servlet spec has a broken classloader concept.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: OK
PostPosted: Thu Nov 27, 2003 10:12 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
I will copy all the hibernate jars to every webapp WEB-INF/lib that use it. Thanks everyone for your patience.

/Froberg


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.