我正在尝试使用WorkoutCaseIdfrom从两个不同的表返回数据ReportedWorkout,并使用PaymentDatefrom对它们进行排序Payment。
报告锻炼
+-------------------+----------------+
| ReportedWorkoutId | WorkoutCaseId |
+-------------------+----------------+
支付
+-----------+--------------------+--------------+---------------+
| PaymentId | ReportedWorkoutId | PaymentDate | PaymentAmount |
+-----------+--------------------+--------------+---------------+
我想返回数据为:
SELECT * FROM ReportedWorkout
JOIN table2 ON ReportedWorkout.ReportedWorkoutId = Payment.ReportedWorkoutId
WHERE 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:
@Repository
public 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!
慕哥6287543
森栏
相关分类