I'm using JPA2 with Hibernate and try to introduce a common base class for my entities. So far it looks like that:
@MappedSuperclass
public abstract class BaseEntity {
@Id
private Long id;
@Override
public int hashCode() {
// ...
}
@Override
public boolean equals(Object obj) {
// ...
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
}
However, for every table theres a sequence $entityname_seq
which I want to use as my sequence generator. How can I set that from my subclass? I think I need to override @GeneratedValue and create a new SequenceGenerator with @SequenceGenerator.
With EclipseLink, you can use a
Customizer
.DescriptorCustomizer
interface defines a way to customize all the information about a jpa descriptor (aka a persistent entity).and in your mapped superclass:
In JPA that cannot be done with annotations. Annotation itself cannot be overridden. Entity inherits all the mapping information from MappedSuperClass. There is only two annotations that can be used to redefine mappings inherited from mapped superClass:
Neither of them helps with GeneratedValue.
Yes, it is possible. You can override the default generator name with the
@SequenceGenerator
annotation.Sequence (SQL)
Derived class
edit