hibernate框架中一个问题,实现添加数据报错

双人鱼XKQ 发布于 2012/12/19 23:47
阅读 2K+
收藏 0
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:20)
at com.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
at com.pb.hibernate.test.Test.main(Test.java:15)
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:223)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:120)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:15)
... 2 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 10 more
加载中
0
peanutmain
peanutmain

你日志接口用的是slf4j,底层日志实现用的是log4j,根据slf4j的规定,你需要一个slf4j到log4j的转换jar包

peanutmain
peanutmain
回复 @追逐梦想 : 我回答的是针对的第一个错误,但你已经加了slf4j-nop-1.5.2.jar,就不需要加slf4j-log4j12-1.5.8.jar
双人鱼XKQ
双人鱼XKQ
我下载添加了你说的那个slf4j-log4j12-1.5.8.jar出现了下面的情况。。。
双人鱼XKQ
双人鱼XKQ
又出现错误了....
0
逝水fox
逝水fox
 java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder 
双人鱼XKQ
双人鱼XKQ
帮我看看...
双人鱼XKQ
双人鱼XKQ
怎么解决啊?
0
Richard_sun
Richard_sun
缺包,slf.lar,或者工程发部有问题
0
Wentasy
双人鱼XKQ
双人鱼XKQ
看一下新的错误
0
双人鱼XKQ
双人鱼XKQ
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/pb/hibernate/po/Login.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:20)
at com.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
at com.pb.hibernate.test.Test.main(Test.java:15)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/pb/hibernate/po/Login.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 2 more
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:555)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 9 more
Caused by: org.dom4j.DocumentException: Error on line 15 of document  : 元素类型 "class" 必须由匹配的结束标记 "</class>" 终止。 Nested exception: 元素类型 "class" 必须由匹配的结束标记 "</class>" 终止。
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:546)
... 10 more

0
双人鱼XKQ
双人鱼XKQ
大家帮帮我啦。。。
0
双人鱼XKQ
双人鱼XKQ
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/supermanxkq/Desktop/slf4j-nop-1.5.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/supermanxkq/Desktop/slf4j-log4j12-1.5.8%20(1).jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Initial SessionFactory creation failed.org.hibernate.MappingNotFoundException: resource: com/pb/hibernate/po/Login/hbm/xml not found
Exception in thread "main" java.lang.ExceptionInInitializerError
 at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
 at com.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
 at com.pb.hibernate.test.Test.main(Test.java:15)
Caused by: org.hibernate.MappingNotFoundException: resource: com/pb/hibernate/po/Login/hbm/xml not found
 at org.hibernate.cfg.Configuration.addResource(Configuration.java:610)
 at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
 at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
 at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
 at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
 at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
 ... 2 more
0
peanutmain
peanutmain

无效的配置文件,你的Login.hbm.xml配置有错吧

peanutmain
peanutmain
回复 @追逐梦想 :可能是数据库版本、jdbc驱动、方言配置等没有匹配
双人鱼XKQ
双人鱼XKQ
嗯,我的login.hbm.xml在hibernate.cfg.xml中指定映射文件的完整路径的时候写成了login/hbm/xml,然后改过来之后又出现了这个问题。。。
0
双人鱼XKQ
双人鱼XKQ
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Initial SessionFactory creation failed.org.hibernate.HibernateException: Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use
Exception in thread "main" java.lang.ExceptionInInitializerError
 at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
 at com.pb.hibernate.dao.LoginDao.save(LoginDao.java:15)
 at com.pb.hibernate.test.Test.main(Test.java:15)
Caused by: org.hibernate.HibernateException: Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect to use
 at org.hibernate.dialect.resolver.DialectFactory.determineDialect(DialectFactory.java:141)
 at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:97)
 at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:117)
 at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
 at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
 at com.pb.hibernate.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
 ... 2 more
Caused by: java.sql.SQLException: 不支持的特性
 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
 at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
 at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:689)
 at oracle.jdbc.OracleDatabaseMetaData.getDatabaseMajorVersion(OracleDatabaseMetaData.java:4442)
 at org.hibernate.dialect.resolver.DialectFactory.determineDialect(DialectFactory.java:131)
 ... 8 more
返回顶部
顶部