I have to perform a delete operation through an API. Once I call that API it gives some nested exceptions like.
could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
and
could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
My Entities like
@Entity
@Table(name = "EMPLOYEE")
public class Employee {
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
@Id
private String emp_id;
@OneToMany(targetEntity = SalaryAllowances.class, cascade = CascadeType.ALL, orphanRemoval = true)
@Fetch(FetchMode.SELECT)
@JoinColumn(name = "emp_id", referencedColumnName = "emp_id")
private List<SalaryAllowances> salaryAllowances;
private String firstName;
private String lastName;
//...
}
and the mapped entity is like
@Entity
@Table(name = "Allowances")
public class SalaryAllowances {
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
@Id
private String allowanceId;
private String name;
private Double amount;
// ...
}
Here is my repository class.
@Repository
public interface EmployeeRepository extends CrudRepository<Employee, Long> {
@Modifying
@Query("DELETE FROM Employee e WHERE e.emp_id = :emp_id")
void deleteEmployee(@Param("emp_id") String emp_id);
}
Can anyone help me to figure this out?
Thanks.