如何解决JPA表达式可基于实体删除记录
我正在尝试根据实体从数据库中删除记录。
我有List,我将它作为参数传递给JPA存储库删除方法。
但是我收到以下异常:
未找到类型为StudentEntity的属性!
表架构:
studentId |学生姓名| studentRollNo |地址
学生实体:
@Entity
@Getter
@Setter
@IdClass( PK.class )
@Table("student_data",schema= "public")
public class StudentEntity{
@Id
@Column("studentId")
private Integer studentId;
@Id
@Column("studentName")
private String studentName;
@Id
@Column("studentRollNo")
private Integer studentRollNo;
@Column("address")
private String address;
}
组合键:
public class PK implements Serializable{
private Integer studentId;
private String studentName;
private Integer studentRollNo;
}
仓库:
@Repository
public interface StudentRepo extends JpaRepository<StudentEntity,PK>{
@Transactional
@Modifying
int delete(@Param("tobeDeletedEntities") List<StudentEntity> tobeDeletedEntities);
}
请帮助。
解决方法
我认为您不需要写那个。 JpaRepository已经具有该功能。
JpaRepository.deleteInBatch(Iterable entities)
只需致电:
studentRepo.deleteInBatch(listOfStudentsToDelete);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。