我想使用 crudRepository 从数据库中删除一个条目。我有一个 Timecard 实体,它与 Task 实体具有一对多关系,而 Task 与 Project 具有一对多关系。我想根据 taskId 和 projectId 删除数据库的一个元素。
以下是实体的定义:
@Entity
@Table(name = "timecards")
public class TimeCard{
@Getter @Setter
@Column(name = "timecard_id", nullable = false)
@SequenceGenerator(name = "timecardSequence", sequenceName = "timecardIdSequence", allocationSize = 1, initialValue = 1)
@GeneratedValue(generator = "timecardSequence")
@Id
private Long timeCardId;
@Getter @Setter
@ManyToOne
@JoinColumn(name = "task_id", nullable = false, referencedColumnName = "id")
private Task task;
}
@Entity
@Table(name = "tasks")
public class Task{
@Getter @Setter
@Column(name = "id", nullable = false)
@SequenceGenerator(name = "taskSequence", sequenceName = "taskIdSequence", allocationSize = 1, initialValue = 1)
@GeneratedValue(generator = "taskSequence")
@Id
private Long id;
@Getter
@Setter
@Column(name = "task_id", nullable = false)
private int taskId;
@Getter @Setter
@ManyToOne
@JoinColumn(name = "project_id", referencedColumnName = "project_id")
private Project project;
}
@Entity
@Table(name = "projects")
public class Project implements Serializable {
@Getter @Setter
@Column(name = "project_id", nullable = false)
@Id
private Long projectId;
@Repository
public interface TimeCardRepository extends CrudRepository<TimeCard, String>{
public void deleteTimeCardByTaskTaskIdAndTaskProjectProjectId(int taskId, Long projectId);
}
deleteTimeCardByTaskTaskIdAndTaskProjectProjectId 是我的属性表达式,但不幸的是我收到以下错误消息:
Caused by: io.quarkus.spring.data.deployment.UnableToParseMethodException: Entity com.timecardservice.timecard.TimeCard does not contain a field named: TaskProject_ProjectId. Offending method is deleteTimeCardByTaskTaskIdAndTaskProjectProjectId
我检查了https://evonsdesigns.medium.com/spring-jpa-one-to-many-query-examples-281078bc457b的横断点,但我收到了相同的错误消息。
执行此查询的正确方法是什么?