我想要一个这样的查询:
@Query("select p from Purchase join p.customer c where c.username = :username and p.getPurchaseDate() >= :fromDate and p.getPurchaseDate() < :toDate")
List<Purchase> findByUsernameAndByDate(@Param("fromDate") Date fromDate, @Param("toDate") Date toDate, @Param("username") String username);
其中getPurchaseDate()是查询内部的方法调用。我知道我做不到,但是我想知道是否有其他方法可以做到这一点。问题在于,getter方法返回的购买日期不是类Purchase的属性。
如果需要,这是购买类别:
@Entity
public class Purchase {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer purchaseId;
@ManyToOne
@JoinColumn(name = "customer_id")
private User customer;
@ElementCollection
@MapKeyEnumerated(value = EnumType.STRING)
@CollectionTable(name = "purchase_status")
@MapKeyColumn(name = "status")
@Column(name = "date")
private Map<PurchaseStatus, Date> statusTransitions = new HashMap<>();
.
.
.
购买日期在statusTransitions地图中。