After extending entity with Auditable i can’t remove elements JpaRepository
@Entity
@Table(name = "users")
@SuperBuilder
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class User extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "user")
@ToString.Exclude
@EqualsAndHashCode.Exclude
private List<Event> events;
}
@Entity
@Table(name="events")
@SuperBuilder
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Event extends Auditable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String name;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
}
@SuperBuilder
@EqualsAndHashCode
@ToString
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class Auditable {
@Version
private Long version;
@CreatedBy
private String creator;
@LastModifiedBy
private String editor;
@CreatedDate
private LocalDateTime creationDateTime;
@LastModifiedDate
private LocalDateTime updateDateTime;
}
I tried to delete event, it runs, but element is still in database. Without the auditable it is working as it should and deleting event properly. Classes have @Getter, @Setter, @NoArgsConstructor and @AllArgsConstructor
this.repository.deleteById(id);
New contributor
lemonlambo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.