且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用除SINGLE_TABLE以外的任何其他Hibernate继承策略时,JVM会崩溃

更新时间:2023-02-19 21:53:08

试试Java 1.6.0_20,并检查是否可行。你已经发现了一个JVM错误,并且返回6个小版本可能足以让它运行。



你很幸运,这个错误是可重现的,所以创建一个最小的测试用例并将其发布到Oracle错误数据库。


Ok, this is probably a longshot but here goes.

In Java (JRE 1.6.0_26-b03) I have two classes, SuperControl and its subclass SubControl. They both need to be persistent objects and I'm using Hibernate Annotations to achieve this. I have approximately 210 classes that are being persisted correctly. Except one isn't.

My problem is that SubControl refuses to inherit in any way besides SINGLE_TABLE. When I say "refuses", I mean that the entire JRE crashes.

This is a bit problematic because I'd really prefer SuperControl to be a mapped superclass of SubControl. SuperControl can also be a persistent entity in its own right. The strange thing is that I have an exactly parallel hierarchy in my code elsewhere that works correctly.

This is what I want:

@Entity
@MappedSuperclass
public class SuperControl extends ItsSuperClass {
  // ...
}

@Entity
public class SubControl extends SuperControl {
  // ...
}

but it bombs out with the error

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (c1_Optimizer.cpp:271), pid=5456, tid=1260
#  guarantee(x_compare_res != Constant::not_comparable) failed: incomparable constants in IfOp
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Client VM (20.1-b02 mixed mode, sharing windows-x86 )
# An error report file with more information is saved as:
# C:\eclipse\hs_err_pid5456.log

Without supplying any inheritance hint, Hibernate defaults to SINGLE_TABLE (which I can tell thanks to the creation of a DTYPE column). I can explicitly specify this without the JVM crashing.

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class SuperControl extends ItsSuperClass {
  // ...
}

@Entity
public class SubControl extends SuperControl {
  // ...
}

The worst part is that if I remove the SubControl class ENTIRELY, or even just its mapping in the hibernate.cfg.xml file, the JVM still crashes. This leads me to believe that there's some kind of hidden linkage between SuperControl and SubControl. Maybe something cached in Eclipse or the like. I've restarted Eclipse, done several clean-and-builds, and even restarted my machine, and the problem's still there.

Any ideas? I've been working on this for hours and have gotten nowhere.

Thanks!

Try Java 1.6.0_20, and check if that works. You have found a JVM bug, and going back 6 minor versions might be enought to get this running.

You are lucky in the way that this bug is reproducable, so create a minimal testcase and post it to the Oracle bug database.