【问题标题】:Exception in thread "main" java.lang.NoClassDefFoundError:javax/persistence/Cacheable线程“main”中的异常 java.lang.NoClassDefFoundError:javax/persistence/Cacheable
【发布时间】:2015-05-07 12:02:24
【问题描述】:

我在 java 中有一个简单的休眠用于创建表。执行时异常。

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);
    }
}

例外是:

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)

【问题讨论】:

    标签: java hibernate console-application


    【解决方案1】:

    在项目构建路径中添加hibernate-jpa-2.0-api-1.0.0.Final 库。从Maven Repo 下载。其他版本可用here

    【讨论】:

      【解决方案2】:

      这个错误可以通过包含 hibernate-jpa-2.0-api-1.0.0 来解决。在你的类路径中,可以在 hibernate-distribution-3.5.3-Final\lib\jpa 中找到。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多