1

我在休眠时遇到了一个非常大的问题。

我的继承策略在作为 jpa 提供程序的 eclipselink 下完美运行,无论是在 glassfish 和 jboss 应用程序服务器下,但是当我切换到休眠状态时,一切都变得混乱。

我在这里阅读了几篇文章,但没有一个能解决我的问题。

以下是堆栈跟踪。

Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_21]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_21]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]
Caused by: java.lang.ClassCastException: org.hibernate.mapping.UnionSubclass cannot be cast to org.hibernate.mapping.RootClass
    at org.hibernate.cfg.annotations.PropertyBinder.bind(PropertyBinder.java:210)
    at org.hibernate.cfg.annotations.PropertyBinder.makePropertyValueAndBind(PropertyBinder.java:201)
    at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2011)
    at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:765)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:684)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3406)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3360)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1334)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    ... 3 more

我已确保没有子类定义另一个 @Id 列(无论如何,netbeans 将始终为我标记此错误)

这是我拥有的一组继承:

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@PartialSecurity
public abstract class DataVerification extends SecureEntity implements Serializable {

  private static final long serialVersionUID = IdGenerator.serialVersionUID(DataVerification.class);
  @Id
  private Long verificationId = IdGenerator.generateId();
  @Column(length = 50, nullable = false)
  private String verificationCode;
  private String verifiedId;
  private boolean verified;
  @Temporal(javax.persistence.TemporalType.TIMESTAMP)
  private Calendar verificationDate;
  private DataVerificationType dataVerificationType;
  private VerificationMethod verificationMethod;
  @OneToOne
  private Account verifiedBy;
  @OneToOne
  private Account approvedBy;


/**
 *
 * @author marembo
 */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class OnlineDataVerification extends DataVerification implements Serializable {
  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @Ignore
  private List<UploadFile> verificationFiles;


    /**
     *
     * @author marembo
     */
    @Entity
    public class IncomeDataVerification extends OnlineDataVerification implements Serializable {

      private static final long serialVersionUID = IdGenerator.serialVersionUID(IncomeDataVerification.class);
      private IncomeSource incomeSource;
      private String occupation;


/**
 *
 * @author marembo
 */
@Entity
public class AgentDataVerification extends OnlineDataVerification implements Serializable {

  @Column(length = 2048, nullable = false)
  private String comment;
  private String verificationTransaction = IdGenerator.generateStringId();

谢谢

4

1 回答 1

0

您的堆栈跟踪引起了对休眠版本不一致问题的怀疑。如果您将应用程序部署到 JBoss,那么 JBoss 已经拥有自己的休眠模式。如果你的战争还伴随着不同版本的 Hibernate,那么类路径上加载的实际类可能会不一致,从而导致各种问题。

通常最佳实践是,如果您要部署到已经提供休眠功能的容器,请不要将其捆绑在您的战争中(例如:将依赖关系标记为在 maven pom 上提供)

于 2013-07-12T15:06:27.670 回答