Hibernate Envers:嵌入式扩展MappedSuperClass在启动时引发异常

时间:2015-03-25 14:05:28

标签: java hibernate hibernate-envers

我目前正在尝试在我的项目中使用Hibernate Envers,但是我遇到了以下异常。我认为这是因为MedicalSummaryId不包含数据并扩展了映射的超类,但我看不出如何解决它。

我正在使用Hibernate 4.3.8.Final。

例外:

Caused by: org.hibernate.MappingException: Type not supported: org.hibernate.type.ComponentType
    at org.hibernate.envers.configuration.internal.metadata.IdMetadataGenerator.addIdProperties(IdMetadataGenerator.java:97)
    at org.hibernate.envers.configuration.internal.metadata.IdMetadataGenerator.addId(IdMetadataGenerator.java:161)
    at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:598)
    at org.hibernate.envers.configuration.internal.EntitiesConfigurator.configure(EntitiesConfigurator.java:107)
    at org.hibernate.envers.configuration.spi.AuditConfiguration.<init>(AuditConfiguration.java:130)
    at org.hibernate.envers.configuration.spi.AuditConfiguration.getFor(AuditConfiguration.java:180)
    at org.hibernate.envers.event.spi.EnversIntegrator.integrate(EnversIntegrator.java:76)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:312)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
    ... 87 more

MedicalHistory.java

@Entity
@Audited
public class MedicalHistory extends BaseEntity {
    @EmbeddedId MedicalHistoryId medicalHistoryId = new MedicalHistoryId();
    @NotNull String description;
}

MedicalHistoryId.java

@Embeddable
public class MedicalHistoryId implements Serializable {
    @NotNull public MedicalSummaryId medicalSummaryId;
    @NotNull public long id = 0;
}

MedicalSummaryId.java

@Embeddable
public class MedicalSummaryId extends AggregateRootId{
     // no data
}

AggregateRoot.id

@Embeddable
@MappedSuperclass
public class AggregateRootId implements Serializable {
    protected Integer id;
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

问题似乎来自复合键,因此,我找到了一个不令人满意的解决方法,而不是使用复合键,如果我使用一个简单的键就可以了。