I have modified the design of CPRQ a bit to help my database pattern
I have an Employee table and a Department table. Both have common properties
@Column(name="tenantIDPKFK")
private Integer tenantIdpkfk;
@Column(name="status")
private Integer status;
So I created a base class ABaseEntity like below
public class ABaseEntity {
public ABaseEntity() {
}
public ABaseEntity(int tenantIdpkfk, int status) {
this.tenantIdpkfk = tenantIdpkfk ;
this.status = status ;
}
@Column(name="tenantIDPKFK")
private Integer tenantIdpkfk;
@Column(name="status")
private Integer status;
I have extended EmployeeEntity with ABaseEntity
@Entity
@Table(name = "employee")
public class EmployeeEntity extends ABaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "first_name")
@NotEmpty(message = "Please provide a name")
@NotBlank
private String firstName;
My CommandHandler runs the following code
EmployeeEntity savedEmployeeEntity = this.employeeRepository.saveAndFlush(employee);
this.mediator.emit(new EmployeeCreatedEvent(savedEmployeeEntity.getId()));
Database saved the object, but only id
, firstname
. Does not save tenant
and status
columns.
I know I am missing something silly. Please help.
EDIT
Adding @MappedSuperclass
to the ABaseEntity class fixed the issue.
@MappedSuperclass
public class ABaseEntity {...}