Hibernate:使用子查询查询联接
我需要将下面的查询转换为hibernate-Hibernate:使用子查询查询联接,hibernate,Hibernate,我需要将下面的查询转换为hibernate- select * from ep_batch eb INNER JOIN ep_slide slide ON eb.batch_scanner_id = slide.slide_batch_id WHERE eb.batch_scanner_id = 1 AND eb.batch_status = ( IF((SELECT count(batch_id) as cnt from ep_batch WHERE batch_scanner_id =
select * from ep_batch eb
INNER JOIN ep_slide slide ON eb.batch_scanner_id = slide.slide_batch_id
WHERE eb.batch_scanner_id = 1 AND
eb.batch_status =
(
IF((SELECT count(batch_id) as cnt from ep_batch WHERE batch_scanner_id = 1) =1,'Ready','In Progress')
) ;
我有“幻灯片”和“批次”pojo代表ep_幻灯片和ep_批次。连接注释为-
@OneToMany(mappedBy = "batch")
private Set<Slide> slides;
@ManyToOne
@JoinColumn(name = "batchId")
private Batch batch;
我还没有执行,但是您可以尝试下面的HQL,适当地替换实体属性
SELECT b FROM Batch b, Slide s
WHERE b.batch_scanner_id = s.slide_batch_id AND
b.batch_status =
(CASE WHEN ((SELECT COUNT(bt.batch_id) FROM Batch bt WHERE bt.batch_scanner_id = 1) = 1) THEN 'Ready'
ELSE 'In Progress'
END);
SELECT b FROM Batch b, Slide s
WHERE b.batch_scanner_id = s.slide_batch_id AND
b.batch_status =
(CASE WHEN ((SELECT COUNT(bt.batch_id) FROM Batch bt WHERE bt.batch_scanner_id = 1) = 1) THEN 'Ready'
ELSE 'In Progress'
END);