目前我有一个使用 JpaRepository<Employee, EmployeePk> 的 Spring Boot 应用程序,假设 EmployeePk 是名字,姓氏。有没有办法通过主键字段删除而不必指定自定义@Query?如果多个人被命名为“John”,则可以删除多行。
例子:
@Repository
public interface EmployeeRepository extends JpaRepository<Employee, EmployeePk> {
@Transactional
@Modifying
@Query(value = "DELETE FROM Employee e WHERE e.EmployeePk.firstname = :firstname ")
void deleteAllByEeId(String firstname);
}
如
void deleteByEmployeePkWhereFirstname(String firstname);
员工类和嵌入式 PK
public class Employee {
@EmbeddedId
private EmployeePK employeePK;
private LocalDate birthDate;
}
public class EmployeePK implements Serializable {
public static final long serialVersionUID = 1L;
private String firstName;
private String lastName;
}