首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

hibernate实例有关问题

2013-06-25 
hibernate实例问题SLF4J: Failed to load class org.slf4j.impl.StaticLoggerBinder.SLF4J: Defaulting

hibernate实例问题
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.
org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2146)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2127)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
at hibernate.TestUser.main(TestUser.java:14)

编译如下的test文件报上面的错误,
package hibernate;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class TestUser {
public static void main(String[] args) {

try {
SessionFactory sf=new Configuration().configure().buildSessionFactory();//错误提示的14行代码。
Session session=sf.openSession();
Transaction ts=session.beginTransaction();
User user=new User();
user.setUsername("Hibernate");
user.setPassword("123");
session.save(user);
ts.commit();
session.close();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}


*************************************************************************

hibernate.cfg.xml是同一包hibernate下的配置文件。


[解决办法]
hibernate.cfg.xml直接放在src下
[解决办法]
方法1: 

引用:
hibernate.cfg.xml直接放在src下

方法二: 将代码改为 ,其中path 是存放hibernate.cfg.xml 文件的路劲
String path="";
SessionFactory sf=new Configuration().configure(path).buildSessionFactory();/

热点排行