我的实体具有以下结构:

@MappedSuperclass
public abstract class BaseEntity {
  @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGenerator")
  private Long id;
}

@MappedSuperclass
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@SequenceGenerator(name = "seqGenerator", sequenceName = "DICTIONARY_SEQ")
public abstract class Intermed extends BaseEntity {}

@Entity
public class MyEntity1 extends Intermed {}

@Entity
public class MyEntity2 extends Intermed {}

我有以下异常:
    Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path resource [context/applicationContext.xml]:
Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown Id.generator: seqGenerator

当我在Intermed类上将@MappedSuperclass更改为@Entity时,一切正常。
使用@MappedSuperclass和@SequenceGenerator是否有任何问题?还是我错过了什么?

最佳答案

这是JPA 1.0规范关于SequenceGenerator注释的内容:



映射的父类(super class)不是实体。因此,根据我阅读规范的方式,您不可能做任何事情。将Intermed类设为一个实体,或者将SequenceGenerator放在子类上。

09-13 00:51