I have a UserAuthenticationEntity extending from BaseEntity.
@MappedSuperclass
public class BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_seq_generator")
@SequenceGenerator(name = "user_seq_generator", sequenceName = "user_seq", allocationSize = 1)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
@Entity
@Table(name = "user_authentication")
public class UserAuthenticationEntity extends BaseEntity {
private String username;
private String password;
public UserAuthenticationEntity(String username, String password){
this.username = username;
this.password = password;
}
...
...
}
All future entities will extend BaseEntity class.
Is it possible that all entities inherit id property from BaseEntity class yet have separate sequences to generate primary keys?
I know this is a wired scenario but I think having a base entity class is a great place to define id property for all entity classes but not being able to use different sequences is a kind of deal breaker. Not sure it can be done.
Any alternative/better design for entity classes is also welcome.