【问题标题】:Writing a NON-EXIST query using JPA / Criteria使用 JPA / Criteria 编写 NON-EXIST 查询
【发布时间】:2012-11-17 08:38:10
【问题描述】:

我正在运行一个模拟销售机票的应用程序。
使用简单模式 (1-n):

SEAT
------
id_seat
description
position

BOOKING
---------
id
customer
id_seat

我想使用 JPA API 或 Criteria 生成一个查询,它为我提供了所有可用 SEAT 的列表。即,BOOKING 表中不存在(未预订)的所有 SEAT 对象。 (SEAT.id_seat = BOOKING.id_seat)

谁能给我一个线索,哪个是生成此类查询的最佳选择?

【问题讨论】:

    标签: jpa jpa-2.0 criteria-api


    【解决方案1】:
    select seat from Seat seat 
    where seat.id not in (
        select seat2.id from Booking booking 
        inner join booking.seat seat2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-01
      • 2022-01-15
      • 1970-01-01
      • 2020-12-07
      • 2015-02-21
      • 2012-08-19
      • 1970-01-01
      相关资源
      最近更新 更多