gpt4 book ai didi

java - 使用 Hibernate 获取具有最大 id 值的实体

转载 作者:搜寻专家 更新时间:2023-10-30 22:09:42 24 4
gpt4 key购买 nike

我想获取 giftManagement.point_To 的最大值,它来自另一个表。但它不是从表中提取数据。

@Id
@SequenceGenerator(name = "seq_offer_gen", sequenceName = "seq_offer")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_offer_gen")
private long id;

@ManyToOne
@JoinColumn(name = "customer_id", nullable = false)
private Customer customer;

@ManyToOne
@JoinColumn(name = "gift_management_id", nullable = false)
private GiftManagement giftManagement;

@Column(name = "sms_delivery_status", nullable = false)
private String smsDeliveryStatus;

@Column(name = "offer_received_status", nullable = false)
private String offerReceivedStatus;






Offer offer = (Offer) session.createQuery("FROM Offer where customer.id =:customerId and max(giftManagement.point_To)")
.setParameter("customerId", id)
.uniqueResult();

最佳答案

像这样尝试:

Offer offer = (Offer) session.createQuery(
"select o " +
"from Offer o " +
"where o.id = ( select max(g.point_To) from Offer o1 join o1.giftManagement g where o1.customer.id =:customerId ) ")
.setParameter("customerId", id)
.uniqueResult();

关于java - 使用 Hibernate 获取具有最大 id 值的实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34739475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com