Java 中的 IncompleteClassChangeError 异常是什么?
我正在开发一个小型应用程序,我正在尝试使用 Hibernate Annotations 来映射我的实体。当我遇到这个异常时,我想测试一切是否正常:
Exception in thread "main" java.lang.ExceptionInInitializerError
at fr.cc2i.intervention.dao.main.Main$HibernateUtil.<clinit>(Main.java:48)
at fr.cc2i.intervention.dao.main.Main.test(Main.java:21)
at fr.cc2i.intervention.dao.main.Main.main(Main.java:32)
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at fr.cc2i.intervention.dao.main.Main$HibernateUtil.<clinit>(Main.java:44)
... 2 more
有人可以解释一下这个异常是什么吗?这是我第一次看到它。 这是我的应用程序的主要内容:
package fr.cc2i.intervention.dao.main;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import fr.cc2i.intervention.dao.beans.Client;
import fr.cc2i.intervention.dao.beans.Contrat;
public class Main {
public static void test(){
Client c = new Client();
c.setCode("123343");
c.setAdresse("fkhdhdmh");
c.setNom("dgsfhgsdfgs");
c.setPhone("53456464");
c.setContrat(new Contrat());
Session session = HibernateUtil.getSession();
session.beginTransaction();
session.save(c);
session.getTransaction().commit();
}
/**
* @param args
*/
public static void main(String[] args) {
Main.test();
}
public static class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new AnnotationConfiguration()
.configure().buildSessionFactory();
} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession()
throws HibernateException {
return sessionFactory.openSession();
}
}
}
我的 hibernate 配置非常简单:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping package="fr.cc2i.intervention.dao.beans.Client" />
<mapping class="fr.cc2i.intervention.dao.beans.Contrat" />
<mapping class="fr.cc2i.intervention.dao.beans.Intervention" />
<mapping class="fr.cc2i.intervention.dao.beans.Technicien" />
</session-factory>
</hibernate-configuration>
这是我正在使用的 hibernate maven 依赖项:
<properties>
<org.springframework.version>3.0.3.RELEASE</org.springframework.version>
<hibernate.version>3.6.0.Beta1</hibernate.version></properties>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
有人可以帮助我吗?
i am working on a small application and I am trying to use Hibernate Annotations to map my entities. I wanted to test if everything is alright when i got this exception :
Exception in thread "main" java.lang.ExceptionInInitializerError
at fr.cc2i.intervention.dao.main.Main$HibernateUtil.<clinit>(Main.java:48)
at fr.cc2i.intervention.dao.main.Main.test(Main.java:21)
at fr.cc2i.intervention.dao.main.Main.main(Main.java:32)
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at fr.cc2i.intervention.dao.main.Main$HibernateUtil.<clinit>(Main.java:44)
... 2 more
Can someone explain what is this exception ? This is the first time i see it.
Here is the main of my application :
package fr.cc2i.intervention.dao.main;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import fr.cc2i.intervention.dao.beans.Client;
import fr.cc2i.intervention.dao.beans.Contrat;
public class Main {
public static void test(){
Client c = new Client();
c.setCode("123343");
c.setAdresse("fkhdhdmh");
c.setNom("dgsfhgsdfgs");
c.setPhone("53456464");
c.setContrat(new Contrat());
Session session = HibernateUtil.getSession();
session.beginTransaction();
session.save(c);
session.getTransaction().commit();
}
/**
* @param args
*/
public static void main(String[] args) {
Main.test();
}
public static class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new AnnotationConfiguration()
.configure().buildSessionFactory();
} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex);
}
}
public static Session getSession()
throws HibernateException {
return sessionFactory.openSession();
}
}
}
My hibernate config is very simple :
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping package="fr.cc2i.intervention.dao.beans.Client" />
<mapping class="fr.cc2i.intervention.dao.beans.Contrat" />
<mapping class="fr.cc2i.intervention.dao.beans.Intervention" />
<mapping class="fr.cc2i.intervention.dao.beans.Technicien" />
</session-factory>
</hibernate-configuration>
Here is the hibernate maven dependency i am using :
<properties>
<org.springframework.version>3.0.3.RELEASE</org.springframework.version>
<hibernate.version>3.6.0.Beta1</hibernate.version></properties>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Can someone help me please ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这意味着在某个时刻,
接口
被更改为类
,但原始接口的实现者没有被修改和重新编译以适应这种(不兼容的)更改。例如,考虑以下类型:
现在假设
Fooable
被修改并重新编译,但FooImpl
却没有:It means that at some point, an
interface
was changed to aclass
, but an implementer of the original interface was not modified and recompiled to accommodate this (incompatible) change.For example, consider the following types:
Now suppose
Fooable
is modified and recompiled, butFooImpl
is not:JDK 1.4 支持已在 3.6 中删除。因此,Hibernate Annotations 已合并回 Core,不再需要同时拥有
Configuration
和AnnotationConfiguration
,并且后者不应在 3.6.x 中使用(实际上,您可能应该使用 JPAEntityManager
,而不是核心 API,但这是另一个故事了)。但我真正的建议是使用 Hibernate 的 3.5.x 分支,而不是 3.6.x。正如我们已经看到的,Hibernate 团队在 3.6 中引入了重大更改,这是在 Beta 版之上的,除非您密切关注这些更改,否则您将面临一些惊喜,并且在互联网上找不到太多资源然而。只需使用 Hibernate 3.5(撰写本文时为 3.5.5-Final)。
JDK 1.4 support has been dropped in 3.6. So Hibernate Annotations has been merged back into Core and there is no more need to have both
Configuration
andAnnotationConfiguration
and the later should not be used in 3.6.x (actually, you should probably use the JPAEntityManager
, not the core API, but this is another story).But my real advice would be to use the 3.5.x branch of Hibernate, not the 3.6.x. As we already saw, the Hibernate team is introducing big changes in 3.6, which is on top of that still in Beta, and unless you are following the changes closely, you'll face some surprises and won't find many resources on the internet yet. Just use Hibernate 3.5 (3.5.5-Final at the time of writing this).
仔细检查您的所有库是否兼容。尝试使用 Hibernate 的稳定版本进行相同的操作,测试版可能存在缺陷,或者 hibernate 3.6.0 beta POM 有一些不兼容的依赖项。
尝试在没有 Maven 的情况下使用来自官方服务器的 hibernate 3.6.0 beta1 库来构建它。
好的 - 您的问题不是错误,而是新功能。 Hibernate 3.6.0 Beta2 的发行说明指出了对之前 Beta 版的重大更改: AnnotationConfiguration 现已完全弃用。因此,如果您想保留 3.6.0 版本,您应该 (a) 更新到最新的测试版 (Beta3),并且 (b) 不要继续使用 AnnotationConfiguration。
Double check if all your libraries are compatible. Try the same with a stable version of hibernate, there's a chance that the beta is defect or the hibernate 3.6.0 beta POM has some incompatible dependencies.
Try to build it without maven and with hibernate 3.6.0 beta1 libraries from the official servers.
OK - your problem is not a bug but a new feature. The release notes for Hibernate 3.6.0 Beta2 note a major change to the previous beta: the AnnotationConfiguration is now totally deprecated. So you should (a) update to the most recent beta (Beta3) if you want to keep a 3.6.0 version and (b) do not continue using the AnnotationConfiguration.
是的,埃里克森正确地识别了这个问题。
这可能是由于类路径中存在同一类型定义的两个冲突版本造成的。例如,library-version2.jar 定义了一些内容,但您的类路径中也有library-version5.jar。
在运行时,这会导致埃里克森描述的痛苦和折磨。
Right, erickson has identified the issue correctly.
This is likely caused by having two conflicting versions of the same type definition in your classpath. For example, library-version2.jar defines some stuff, but you've also got library-version5.jar in your classpath.
At runtime, this results in the pain and suffering erickson describes.
我写这篇文章是为了帮助任何人查找此错误。有时,来自 Spring Roo 的 jar 文件生成的 pom.xml 与 Tomcat 服务器运行时库发生冲突,并在单元测试期间产生此错误。在构建像 Flex 这样的前端技术时,服务器运行时库不需要出现在类路径中,因此只需从类路径中删除服务器运行时库即可。
I write this to help whoever lookup to this error . Sometimes jar files coming from Spring Roo generated pom.xml and Tomcat Server Runtime libraries conflict and produced this error during unit testing. While building frontend technology like Flex, Server runtime libraries are not necessary to present in the classpath, so simply remove the Server runtime libraries from classpath.
您使用哪个应用程序服务器?可能是重复的或冲突的休眠 jar。
Which application server are you using? Could be a duplicate or conflicting hibernate jar.