I think I can aswer your third question.
One common way to do what you want (avoid duplicating ID mapping) is to create a common superclass that holds the annotated id
and version
(for optimistic locking) fields, and then have all persistent objects extend this superclass.
To ensure the superclass is not considered an Entity on its own, it must be annotated with @MappedSuperclass
.
Here is a sample (sorry for typos, I don't have an IDE at hand right now) :
@MappedSuperclass
public class PersistentObject {
@Id // Put all your ID mapping here
private Long id;
@Version
private Long version;
}
@Entity
public class SimpsonsFamily extends PersistentObject {
// Other SimpsonFamily-specific fields here, with their mappings
}