Can anyone help with this issue. It’s my first time using spring boot, I’m trying to implement inheritance using Joined inheritance strategy. I’ve created an entity called AuditTrackable which is a superclass and User which is a subclass. Its all working well but when I delete a user, the row is deleted from the user table but when I check in the audittrackable table, the corresponding row referenced by the user_id is still is still appearing. I’ve a lot of deleted users whose ids are still appearing in the parent table(audittrackable). I would want the delete operation on the user entity to cascade to the parent entity so that a user is completely deleted. Any assistance will greatly be appreciated.
@Data
@AllArgsConstructor
@NoArgsConstructor
@Inheritance(strategy=InheritanceType.JOINED)
public class AuditTrackable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String status;
@Column(updatable=false)
@CreationTimestamp
private Instant createdOn;
@ManyToOne(optional=true)
@JoinColumn(name="created_by",nullable = true,updatable = false)
private AuditTrackable createdBy;
@UpdateTimestamp
private Instant lastUpdatedOn;
@ManyToOne(optional=true)
@JoinColumn(name="last_updated_by",nullable = true)
private AuditTrackable lastUpdatedBy;
}
@Entity
@PrimaryKeyJoinColumn(name = "user_id")
@Data
@EqualsAndHashCode(callSuper=true)
@AllArgsConstructor
@NoArgsConstructor
public class User extends AuditTrackable implements UserDetails {
private static final long serialVersionUID = 1L;
@Column(unique = true,updatable = false,nullable = false)
private String username;
@Column(nullable = false)
private String password;
@Column(nullable = false)
private String firstname;
@Column(nullable = false)
private String lastname;
private String middlename;
// more fields...
}