Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何修复和执行此示例Hibernate程序以创建表_Java_Hibernate - Fatal编程技术网

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

Java 如何修复和执行此示例Hibernate程序以创建表,java,hibernate,Java,Hibernate,我有一个简单的java hibernate程序。它抛出了一个异常,我无法理解 我的代码是: import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.tool.hbm2ddl.SchemaExport; public class TestEmployee { public static void main(String[] args) { AnnotationConfiguration config

我有一个简单的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)**
SLF4J:SLF4J api 1.6.x(或更高版本)与此绑定不兼容。
SLF4J:您的绑定版本为1.5.5或更低版本。
SLF4J:将绑定升级到1.6.x版。或2.0.x
线程“main”java.lang.NoSuchMethodError中出现异常:org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
位于org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
在org.slf4j.LoggerFactory.performinization上(LoggerFactory.java:111)
位于org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
位于org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
位于org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
位于org.hibernate.cfg.Configuration(Configuration.java:197)
位于com.Hibernate.chapter1.TestEmployee.main(TestEmployee.java:10)**
注意:在我的eclipse中,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.logging和log4j。 混合使用不同版本的slf4j-api.jar和slf4j绑定可能会导致问题。例如,如果您使用的是slf4j-api-1.7.12.jar,那么您还应该使用slf4j-simple-1.7.12.jar,使用slf4j-simple-1.5.5.jar将不起作用

从客户的角度来看,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 jar的版本都是相同的。ie(如果您使用的是slf4j-api-1.7.12.jar,那么您还应该使用slf4j-simple-1.7.12.jar,使用slf4j-simple-1.5.5.jar将不起作用。)

将所有slf4j jar更新为最新版本应该可以解决此问题,或者您可以检查所有slf4j jar并替换有问题的一个

下载slf4j的链接如下

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


用slf4j api 1.5.5或更早版本替换slf4j api 1.6.x jar。不得不说这有点伤人,但你误解了非常明显的错误。它声明需要更新绑定,而不是像您声称的那样更新API。@Gimby Thnks。我的回答不清楚,事实上看起来不正确。。这只是用词不当。我重新措辞了我的回答。再次感谢您抽出时间发表评论。