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.  [ 6 posts ] 
Author Message
 Post subject: og4j:WARN No appenders could be found for logger
PostPosted: Tue May 27, 2008 3:10 am 
Newbie

Joined: Tue May 27, 2008 3:03 am
Posts: 3
Location: Athens Greece
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1411)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1433)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1420)
at forum.beans.PopulateMessages.main(PopulateMessages.java:14)


The problem is that the path is ok and the files are there too
for DB2
-----XML File--
<?xml version="1.0"?>
<!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="show_sql">true</property>
<mapping resource="forum/beans/Event.hbm.xml"/>

<mapping resource="forum/beans/Location.hbm.xml"/>
</session-factory>
</hibernate-configuration>
-----Properties file--------------------------


hibernate.connection.username=my username
hibernate.connection.password=my password
hibernate.connection.driver_class=com.ibm.db2.jcc.DB2Driver
hibernate.connection.url=jdbc:db2:db2t
hibernate.dialect=org.hibernate.dialect.DB2Dialect
-----------------------------


Any idea what to do ?
can't find the problem


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 4:28 am 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
Are you using both a properties and a XML file? You should only use one of them. I'm not so sure that the path is OK.

Quote:
Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found

Obviously it can't find hibernate.cfg.xml. How did you specify where to find it? Might be a classpath problem.
You should also do something about the log4j warnings. Did you define log4j.properties? There are lots of tutorials on the net on how to do that.


Top
 Profile  
 
 Post subject: it is an exact code example from the book Beginning hibernat
PostPosted: Tue May 27, 2008 6:53 am 
Newbie

Joined: Tue May 27, 2008 3:03 am
Posts: 3
Location: Athens Greece
Beginning
Hibernate
From Novice to Professional
An introduction to all the new features
of the Hibernate 3.2 persistence API
Covers
Hibernate 3.2
this book must have lots of errors i don't know
yes i have all the files in the package
and the hibernate.cfg.xml
and the hibernate.properties file
should i remove one of them ?


Top
 Profile  
 
 Post subject: it is an exact code example from the book Beginning hibernat
PostPosted: Tue May 27, 2008 6:53 am 
Newbie

Joined: Tue May 27, 2008 3:03 am
Posts: 3
Location: Athens Greece
Beginning
Hibernate
From Novice to Professional
An introduction to all the new features
of the Hibernate 3.2 persistence API
Covers
Hibernate 3.2
this book must have lots of errors i don't know
yes i have all the files in the package
and the hibernate.cfg.xml
and the hibernate.properties file
should i remove one of them ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 9:00 am 
Beginner
Beginner

Joined: Mon Jul 23, 2007 12:37 pm
Posts: 24
I never read anywhere that you should use both. They are alternatives. Did you already try to implement the example in the Hibernate Reference Documentation? I would give you the advice to try that first.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 10:35 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Here's a little snippet from my book, Hibernate Made Easy:

Quote:
Setting up log4J
You will also notice a little log4J error message in my output:

log4j:WARN No appenders could be found for logger
log4j:WARN Please initialize the log4j system properly.

This error is due to the fact that Hibernate is using Log4J, and a properties file that Log4J uses to initialize itself cannot be found on the classpath. The Hibernate download contains a sample log4J.properties file you can place on your classpath that will eliminate this error message and subsequently direct logging entries to the System.out log. Alternatively, you can create your own log4J.properties file with the following settings:

##########################################

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
### set log levels - ###
log4j.rootLogger=warn, stdout log4j.logger.org.hibernate=info
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=debug
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

##########################################

Make sure the file is named log4j.properties, and is placed on the classpath of both the JVM, and the classloader that creates the AnnotationConfiguration object; for me, the log4j.properties file gets placed in the C:\_mycode folder, alongside the all important hibernate.cfg.xml file. Add in this properties file, and then you’ll get all sorts of crazy log messages!


But the problem isn't the log messages, the big problem is that hbiernate.cfg.xml can't be found. It's not good enough to put it on the classpath. It must also be on the classpath of the classloader that initializes your Hibernate Configuration or AnnotationConfiguration object.

You might find this tutorial on how to set up Hibernate on a Windows XP system helpful. It has many examples and shows you the simplest Hibernate configuration possible:

http://www.thebookonhibernate.com/HiberBookWeb/learn.jsp?tutorial=01howtogetstartedwithhibernate

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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