I get this error when configurating my hibernate
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
here is the line of code
Configuration config = new AnnotationConfiguration().configure("HibernatePositionServer.cfg.xml");
and here is my cfg file
<?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.url">jdbc:mysql://[Here i put correct IP:Port]/settings</property>-->
<!--<property name="connection.url">jdbc:mysql://127.0.0.1:1433/settings</property>-->
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="connection.usern开发者_运维问答ame">root</property>
<property name="connection.password">Programa17</property>
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.idle_test_period">150</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_size">1</property>
<!-- DB schema will be updated if needed -->
<property name="hibernate.show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<!--<property name="hbm2ddl.auto">update</property>-->
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
</session-factory>
First ask Google, this is one of the most common Log4J error messages. Simply put: Log4J (logging and monitoring framework) received a logging message from Hibernate and does not know what to do with it (print on console, put in file, ignore...?)
Put file named log4j.xml
in your CLASSPATH root directory (src/main/resource
when using maven) with the following contents:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
<root>
<priority value ="debug" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
I had the same error.There are two causes for this error
There are two log4j jar files in you libraries at different location.
or
The properties file
log4j.properties
is not present in the default package inside your application.
Why this error is popped out is hibernate.config
and log4j should be in same package
I finally got what was happening in my case. It might also help those in Netbeans users facing the same problem coz i have lost a lot of hair for quite some months now. My application had just stopped logging to console so i couldnt debug since the errors were not being displayed.
The answer "There are two log4j jar files in you libraries at different location." was true. Initially i had expected to find 2 files with the name log4xxx.jar of course with different version numbers but no file like that at all was there. You see Netbeans comes prepackaged with Hibernate libraries and many other libraries of course. So when developing in hibernate applications in Netbeans you DON'T need to manually add your own Hibernate Jars unless of course you need a specific version etc, you can just add the Hibernate library to your application via that right click project - Properties - Libraries - Add Library button . This will add many hibernate Jars in the background/classpath when running and also on Compiling in the dist/lib folder BUT NOT in the lib of the application. In my case i had added both the Hibernate Library AND also copied the generated hibernate jars from dist/lib to lib. This had happened by mistake as i copied libraries from previous application to include in my new application for use there.
So take home point, if in Netbeans, go to your lib folder, if you see jars like hibernate-commons-annotations-x.x.x.Final.jar, hibernate-core-x.x.x.Final.jar,hibernate-entitymanager-x.x.x.Final.jar, hibernate-jpa-2.0-api-x.x.x.Final.jar, hibernate-tools-x.x.x.CR1.jar Remove them and check if error resolves.
精彩评论