我有一个 AbstractEntity 类,它由我的应用程序中的所有实体扩展,基本上充当标识符提供者。
@MappedSuperclass
public class AbstractEntity implements DomainEntity {
private static final long serialVersionUID = 1L;
/** This object's id */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="creation_date", nullable = false, updatable=false)
private Date creationDate = new Date();
/**
* @return the id
*/
public long getId() {
return this.id;
}
/**
* @param id the id to set
*/
public void setId(long id) {
this.id = id;
}
}
我现在有一个案例,我需要为我的几个实体类定义一个单独的 ID,因为它们需要有一个自定义序列生成器。如何做到这一点?
@Entity
@Table(name = "sample_entity")
public class ChildEntity extends AbstractChangeableEntity {
@Column(name = "batch_priority")
private int priority;
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}