@SequenceGenerator on class annotated with @MappedSuperclass

前端 未结 2 1656
情话喂你
情话喂你 2021-02-08 03:38

I have following structure of my entities:

@MappedSuperclass
public abstract class BaseEntity {
  @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generat         


        
2条回答
  •  一向
    一向 (楼主)
    2021-02-08 04:11

    Here is what the JPA 1.0 spec says about the SequenceGenerator annotation:

    9.1.37 SequenceGenerator Annotation

    The SequenceGenerator annotation defines a primary key generator that may be referenced by name when a generator element is specified for the GeneratedValue annotation. A sequence generator may be specified on the entity class or on the primary key field or property. The scope of the generator name is global to the persistence unit (across all generator types).

    And a mapped superclass is not an entity. So according to the way I read the spec, what you want to do is not possible. Either make the Intermed class an entity or put the SequenceGenerator on the sub classes.

提交回复
热议问题