[英]MappedSuperclass - Change SequenceGenerator in Subclass without @GeneratedValue on the Superclass
I have a base class:我有一个基础 class:
@MappedSuperclass
public abstract class SuperClass{
@Id
protected Long id;
public Long getId() {
return id;
}
}
The @GeneratedValue is not used since the id is generated using a BackendSession未使用 @GeneratedValue,因为 id 是使用 BackendSession 生成的
There are a lot of inheritance from this class so one can't change it!有很多 inheritance 从这个 class 所以一个不能改变它!
my sub class: I tried to override the getId method我的子 class:我试图覆盖 getId 方法
@Entity
@Table(name = "FTC_DATA")
@SequenceGenerator(name="sequence", sequenceName = "FTC_DATA_SEQ")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class SubClass extends SuperClass {
@Override
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FTC_DATA_SEQ")
public void getId(Long id) {
this.id = id;
}
}
But I fail on IdentifierGenerationException, what am I doing wrong?但是我在 IdentifierGenerationException 上失败了,我做错了什么?
Here's what worked for me.这对我有用。 Remove getId() from SuperClass, remove the @Override from SubClass getId() and move the @Id annotation to the SubClass getId().
从 SuperClass 中移除 getId(),从 SubClass getId() 中移除 @Override,并将 @Id 注解移至 SubClass getId()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.