我正在尝试在我的BaseRepository类中执行此@Query
@Modifying
@Query(value = "DELETE FROM Employee e WHERE e.department.companyBranch.id = :companyBranchId")
void deleteAllByCompanyBranchId(@Param("companyBranchId") Long companyBranchId);
字符串
但我得到了这个例外
Column "D1_0.COMPANY_BRANCH_ID" not found; SQL statement:
delete from employee where d1_0.company_branch_id=? [42122-214]] [delete from employee where d1_0.company_branch_id=?]; SQL [delete from employee where d1_0.company_branch_id=?]] with root cause
org.h2.jdbc.JdbcSQLSyntaxErrorException: Столбец "D1_0.COMPANY_BRANCH_ID" не найден
Column "D1_0.COMPANY_BRANCH_ID" not found; SQL statement:
delete from employee where d1_0.company_branch_id=? [42122-214]
型
我认为它与JPQL约定有某种联系,但我不确定。通过查看我的异常,我可以说查询试图在EMPLOYEE
表中查找COMPANY_BRANCH_ID
字段,但我不确定。
这是我的实体类:
员工:
@Entity
@Table(name = "EMPLOYEE")
@Getter
@Setter
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DEPARTMENT_ID", nullable = false)
private Department department;
}
型
部
@Entity
@Table(name = "DEPARTMENT")
@Getter
@Setter
public class Department {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "COMPANY_BRANCH_ID", nullable = false)
private CompanyBranch companyBranch;
}
型
公司简介
@Entity
@Table(name = "COMPANY_BRANCH")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class CompanyBranch {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
型
1条答案
按热度按时间fafcakar1#
我不确定您是否可以使用这种级别的嵌套查询。
我会试着用这样的词
字符串
这就是你通常在普通sql中所做的那种查询。