我试图使用WorkoutCaseId
中的ReportedWorkout
从2个不同的表中返回数据,并使用PaymentDate
中的Payment
对它们进行排序。
ReportedWorkout
+-------------------+----------------+
| 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!
最佳答案
由于paymentDate不是ReportedWorkoutEntity的属性,因此该错误是有道理的。对于存储库方法,请使用相对于ReportedWorkoutEntity的paymentDate的全限定名称。
因此:findByWorkoutCaseIdOrderBy Payments PaymentDateDesc