1

我需要将以下查询转换为休眠 -

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_slide 和 ep_batch。加入注释为 -

@OneToMany(mappedBy = "batch")
    private Set<Slide> slides;
@ManyToOne
    @JoinColumn(name = "batchId")
    private Batch batch;

我不太确定如何添加带有条件的子查询。我正在尝试类似下面的东西 -

DetachedCriteria subCriteria = DetachedCriteria.forClass(Slide.class);
        subCriteria.setProjection(Projections.count("batchId"));
4

1 回答 1

0

我还没有执行,但是您可以尝试下面的 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);
于 2012-10-22T12:03:04.770 回答