我正在尝试使用WorkoutCaseIdfrom从两个不同的表返回数据ReportedWorkout,并使用PaymentDatefrom对它们进行排序Payment。报告锻炼+-------------------+----------------+| ReportedWorkoutId | WorkoutCaseId |+-------------------+----------------+支付+-----------+--------------------+--------------+---------------+| PaymentId | ReportedWorkoutId | PaymentDate | PaymentAmount |+-----------+--------------------+--------------+---------------+我想返回数据为:SELECT * FROM ReportedWorkoutJOIN table2 ON ReportedWorkout.ReportedWorkoutId = Payment.ReportedWorkoutIdWHERE WorkoutCaseId = '123'ORDER BY PaymentDate DESC@Entity@Table(name = "ReportedWorkout")public class ReportedWorkoutEntity extends BaseEntity{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ReportedWorkoutId") private Long reportedWorkoutId; @Column(name = "WorkoutCaseId") private String workoutCaseId; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "ReportedWorkout") private Set<PaymentEntity> payments = new LinkedHashSet<>();...}@Entity@Table(name = "Payment")public class PaymentEntity extends BaseEntity{ @Id @Column(name = "PaymentId" , nullable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) private long paymentId; @ManyToOne @JoinColumn(name = "ReportedWorkoutId") private ReportedWorkoutEntity reportedWorkout; @Column(name = "PaymentAmount") private BigDecimal paymentAmount; @Column(name = "PaymentDate" , nullable = false) private LocalDate paymentDate;...}我让它通过以下方式返回数据WorkoutCaseId:@Repositorypublic interface ReportedWorkoutRepository extends CrudRepository<ReportedWorkoutEntity, Long> { ReportedWorkoutEntity findByWorkoutCaseId(String workoutCaseId);}但我不知道如何通过 PaymentDate 订购?findByWorkoutCaseIdOrderByPaymentDateDesc 我收到以下错误:Caused by: org.springframework.data.mapping.PropertyReferenceException: No property paymentDate found for type ReportedWorkoutEntity!
2 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
由于 paymentDate 不是 ReportedWorkoutEntity 的属性,因此该错误是有道理的。对于存储库方法,请使用相对于 ReportedWorkoutEntity 的 paymentDate 的完全限定名称。
所以:findByWorkoutCaseIdOrderBy Payments PaymentDateDesc
森栏
TA贡献1810条经验 获得超5个赞
当您想使用另一个实体时,您必须在 @Repository 接口中定义的方法签名中提及它。
正如@churd 所提到的,您必须仅使用该格式创建方法签名。
还有另一个选项,如方法顶部提到的@Query,并在其中定义要执行的sql。
添加回答
举报
0/150
提交
取消