Java Spring/Hibernate-带有AttributeOverrides的表每类继承覆盖子类中的列映射

Java Spring/Hibernate-带有AttributeOverrides的表每类继承覆盖子类中的列映射,java,spring,spring-boot,hibernate,jpa,Java,Spring,Spring Boot,Hibernate,Jpa,注意:由于无法共享实际代码,类和包被重命名 在一个系统中,已经存在以下类别: @Entity class SomeEvent { @Column(name="creation_date") private Instant creationDate; // Other attributes ommitted for clarity } @Entity class AnotherEvent { @Column(name="even

注意:由于无法共享实际代码,类和包被重命名

在一个系统中,已经存在以下类别:

@Entity
class SomeEvent {
    @Column(name="creation_date")
    private Instant creationDate;   
    // Other attributes ommitted for clarity
}

@Entity
class AnotherEvent {
    @Column(name="event_date")
    private Instant eventDate;  
    // Other attributes ommitted for clarity
}
由于他们有共同的祖先,我做了以下继承,这也允许我查询这两个实体:

@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
abstract class BaseEvent {
    private Instant creation;
    // Other attributes ommitted for clarity
}

@Repository
interface BaseEventRepository extends JpaRepository<BaseEvent, Long> {
    List<BaseEvent> findAllOrderByCreationDesc();
}

@Entity
@AttributeOverride(name="creation", column=@Column("creation_date"))
class SomeEvent extends BaseEvent {
    // Other attributes ommitted for clarity
}

@Entity
@AttributeOverride(name="creation", column=@Column("event_date"))
class AnotherEvent {
    // Other attributes ommitted for clarity
}

@实体
@继承(策略=继承类型。每个类的表)
抽象类BaseEvent{
私人即时创作;
//为清晰起见,其他属性未进行说明
}
@存储库
接口BaseEventRepository扩展了JpaRepository{
列出FindAllowerByCreationEsc();
}
@实体
@AttributeOverride(name=“creation”,column=@column(“创建日期”))
类SomeEvent扩展了BaseEvent{
//为清晰起见,其他属性未进行说明
}
@实体
@AttributeOverride(name=“creation”,column=@column(“事件日期”))
第二类事件{
//为清晰起见,其他属性未进行说明
}
运行应用程序时,我收到错误:org.hibernate.AnnotationException:用@heritation注释的实体不能使用@AttributeOverride或@AttributeOverrides:
com.mypackage.SomeEvent

因为我无法更改当前表,所以我希望有某种方法可以将实体与子类中覆盖的创建日期字段进行映射,同时能够通过超类按创建日期进行查询

版本

  • 爪哇1
  • 弹簧护套2.1.3.1释放

这是否回答了您的问题@Smutje不,不幸的是没有。如果我使用映射的Supeclass,我将无法使用它进行查询。JPA不要求对每个类的表\u支持多态性。所以它不是便携式的。