如何修复和执行此示例休眠程序以创建表



我在Java中有一个简单的Hibernate程序。这是一个例外,我听不懂。

我的代码是:

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class TestEmployee {
 public static void main(String[] args) {
    AnnotationConfiguration config = new AnnotationConfiguration();
    config.addAnnotatedClass(Employee.class);
    config.configure("hibernate.cfg.xml");
    new SchemaExport(config).create(true, true);
}
}

错误是:

SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
        at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:197)
        at com.Hibernate.chapter1.TestEmployee.main(TestEmployee.java:10)**

注意:我的日食中的AnnotationConfiguration()有一条线。

原因是什么,我该如何修复?

明确给出了问题的原因

SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x

SLF4J结合指定了诸如SLF4J-JDK14.JAR或SLF4J-LOG4J12.JAR等人工制品,用于将SLF4J与基础的日志记录框架结合到java.util.log.log.loging和log4j。混合混合不同版本的SLF4J-API.JAR和SLF4J结合可能会引起问题。例如,如果您使用的是slf4j-api-1.7.12.jar,则还应使用slf4j-simple-1.7.12.jar,使用slf4j-simple-1.5.5.5。

从客户的角度来看,SLF4J-API的所有版本都是兼容的。使用SLF4J-API-N.JAR编译的客户端代码将使用SLF4J-API-M.JAR完美地运行。对于任何N和M。您只需要确保绑定的版本与Slf4j-api.jar的版本匹配。您不必担心项目中给定依赖项使用的Slf4j-api.jar的版本。您始终可以使用任何版本的slf4j-api.jar,只要Slf4j-api.jar及其绑定匹配的版本,您就应该可以。

要使Hibernate工作您会在项目中添加与Hibernate相关的JAR文件。它包括罐子,其名称以" SLF4J"开头。要解决错误,您需要确保所有SLF4J JARS均为同一版本(如果您使用的是SLF4J-API-1.7.1.12.jar),那么您还应使用Slf4j-simple-1.7.1.12.jar,使用SLF4J-simple-1.5.5.jar无法正常工作。)

将所有SLF4J JARS更新到最新版本应该解决此问题,否则您可以检查所有SLF4J罐子并替换一个有问题的罐子。

下载SLF4J的链接在

下方

http://www.slf4j.org/download.html

有关错误和jar的更多信息,请

找到

http://www.slf4j.org/codes.html

最新更新