简体   繁体   English

线程“主”中的异常java.lang.NoClassDefFoundError:javax / persistence / Cacheable

[英]Exception in thread “main” java.lang.NoClassDefFoundError:javax/persistence/Cacheable

I have a simple hibernate in java for create table. 我在创建表的Java中有一个简单的休眠模式。 It is Exception when execute. 执行时是异常。

public class TestEmployee {
    public static void main(String[] args) {
        AnnotationConfiguration config = new AnnotationConfiguration();
        config.addAnnotatedClass(Employee.class);
        config.configure();

        new SchemaExport(config).create(true, true);
    }
}

The Exception is : 例外是:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/Cacheable
    at  org.hibernate.cfg.AnnotationBinder.determineCacheSettings(AnnotationBinder.java: 988)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:579)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
    at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:1002 )
    at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:130)
    at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)
    at com.Hibernate.chapter1.TestEmployee.main(TestEmployee.java:15)
    Caused by: java.lang.ClassNotFoundException: javax.persistence.Cacheable
    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)

Add hibernate-jpa-2.0-api-1.0.0.Final library in project build path. 在项目构建路径中添加hibernate-jpa-2.0-api-1.0.0.Final库。 Download it from Maven Repo . Maven Repo下载它。 Other versions are available here . 其他版本在这里可用。

This error may get solved by including hibernate-jpa-2.0-api-1.0.0. 通过包含hibernate-jpa-2.0-api-1.0.0,可以解决此错误。 in your classpath which can be found at hibernate-distribution-3.5.3-Final\\lib\\jpa. 在您的类路径中,可以在hibernate-distribution-3.5.3-Final \\ lib \\ jpa中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM