我想获取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/