Hibernate SLF4J 出错 请各位大哥大姐帮忙一下
用户类:package ch03.hibernate;
/**
* @author Fra
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class User {
private int id;
private String username;
private String password;
private String email;
/**
* @return Returns the email.
*/
public String getEmail() {
return email;
}
/**
* @param email The email to set.
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return Returns the id.
*/
public int getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(int id) {
this.id = id;
}
/**
* @return Returns the password.
*/
public String getPassword() {
return password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return Returns the username.
*/
public String getUsername() {
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username) {
this.username = username;
}
}
测试类:
package ch03.hibernate;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
try {
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
User user = new User();
user.setUsername("Hibernate");
user.setPassword("Fra22");
user.setEmail("luxideyao@sina.com");
session.save(user);
tx.commit();
session.close();
} catch (HibernateException e) {
e.printStackTrace();
}
}
}
运行后显示的结果是:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hibernate: select max(id) from Myusertable
Hibernate: insert into Myusertable (username, password, email, id) values (?, ?, ?, ?)
能够插入数据库但是为什么日志文件还是会提示有错误 --------------------编程问答-------------------- 自己研究了很久还是没有搞清楚。等待。。。。。。。。。。。。。牛人 --------------------编程问答-------------------- 可能是没导入jar包 或者版本不对 --------------------编程问答-------------------- 谢谢你!你说的我做过,我导入了slf4j 和 log4j的日志文件。但是运行还是会出现上面的提示。 --------------------编程问答-------------------- 导入slf-nop这个包试试 --------------------编程问答-------------------- 不好意思最近有点忙忘记看帖子了。我现在就是试试 --------------------编程问答-------------------- 有用吗,我也有这个问题 --------------------编程问答-------------------- 这个问题对程序本身没影响。正确的jar应该是使用这三个
补充:Java , Java EE