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

时间:2023-01-19 23:30:35

I have a simple hibernate in java for create table. It is Exception when execute.

我在java for create table中有一个简单的hibernate。执行时是异常。

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)

2 个解决方案

#1


Add hibernate-jpa-2.0-api-1.0.0.Final library in project build path. Download it from Maven Repo. Other versions are available here.

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

#2


This error may get solved by including 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-jpa-2.0-api-1.0.0可能会解决此错误。在你的类路径中,可以在hibernate-distribution-3.5.3-Final \ lib \ jpa中找到。

#1


Add hibernate-jpa-2.0-api-1.0.0.Final library in project build path. Download it from Maven Repo. Other versions are available here.

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

#2


This error may get solved by including 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-jpa-2.0-api-1.0.0可能会解决此错误。在你的类路径中,可以在hibernate-distribution-3.5.3-Final \ lib \ jpa中找到。