Estou com problema com o Log4j
quando executo minha classe main dá o seguinte erro:
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" java.lang.ExceptionInInitializerError
at teste.rum.main(rum.java:37)
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
...
Esta é minha classe main:
package teste;
import java.math.BigDecimal;
import modelo.*;
import org.hibernate.type.BigDecimalType;
import util.*;
import org.hibernate.HibernateException;
import org.hibernate.Session;
/**
*
* @author Paulo Junior
*/
public class rum {
/** Creates a new instance of rum
*
*
*/
public static void main(String[] args){
try{
Transacao transacao = new Transacao();
transacao.setTransacao(BigDecimal.valueOf(1));
transacao.setNomedapagina("teste.jsp");
transacao.setNomedatransacao("testando");
Session session = HibernateUtil.getSession();
session.beginTransaction();
session.save(transacao);
session.getTransaction().commit();
System.out.println("Cadastro realizado com sucesso!");
/*Perfil perfil = new Perfil();
perfil.setPerfil(BigDecimal.valueOf(1));
perfil.setNomeperfil("MaxTop");
Session session = HibernateUtil.getSession();
session.beginTransaction();
session.save(perfil);
session.getTransaction().commit();
System.out.println("Perfil Funcionable!");
*/
}catch (HibernateException e){
e.printStackTrace();
}
}
}
Este é o meu HibernateUtil
package util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
/**
*
*,
* @author Fabiano Santana
*/
public final class HibernateUtil {
private static SessionFactory sessionFactory;
private static final ThreadLocal sessionThread;
static {
sessionThread = new ThreadLocal();
sessionFactory = new Configuration().configure().buildSessionFactory();
}
public static Session getSession() {
Session session = (Session)sessionThread.get();
if (session == null) {
session = sessionFactory.openSession();
sessionThread.set(session);
}
return session;
}
public static void closeSession() {
Session session = (Session)sessionThread.get();
sessionThread.set(null);
if (session != null && session.isOpen()) {
session.flush();
session.close();
}
}
}
e finalmente este é meu log4j:
# File Appender:
log4j.appender.tmpFile = org.apache.log4j.FileAppender
log4j.appender.tmpFile.File = info.log
log4j.appender.tmpFile.layout =org.apache.log4j.PatternLayout
log4j.appender.tempFile.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Loggers:
log4j.rootLogger = warn, tempFile
log4j.org.hibernate = info, tempFile
Estou usando NetBeans com annotation ao invez de mapear via xml e minha aplicação é Web. Tanto o hibernate.cfg.xml quanto o log4j.properties estão no meu WEB-INF
Alguém poderia me dizer o que eu estou fazendo de errado?
Valew
Meu hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@meuip:1521:teste</property>
<property name="hibernate.connection.username">usuario</property>
<property name="hibernate.connection.password">senha</property>
<property name="hibernate.default_schema">teste</property>
<!-- Pool de conexões (usando o bilt-in).-->
<property name="connection.poll_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Gerenciamento automático de sessões-->
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<mapping class="modelo.Perfil"/>
</session-factory>
</hibernate-configuration>