-1

我有几个实体:

TranslationUnit
TranslationValue
区域设置

TranslationUnit 与 TranslationValue 具有多对多关系。
TranslationValue 具有 1-1 与区域设置。
语言环境具有有意义的字段 - jhi_value;
我需要做的是:选择那些 TranslationUnits,即:

1) 没有相关的 TranslationValues(这意味着 - 根本没有翻译) 2) 没有具有特定语言环境的 TranslationValues(例如,“en”)。

我为此构建了 SQL 查询,在我的 Postgres DB 中完美运行:

select * from translation_unit tu where  not exists ( select null from translation_value tv join locale l on tv.locale_id =l.id  where l.jhi_value='en'  and tu.id=tv.translation_unit_id);

我需要为此构建规范(它将与其他现有规范相结合)。

感谢任何帮助。

4

1 回答 1

0

找到了解决方案:

Subquery<TranslationValue> subquery = q.subquery(TranslationValue.class);
                Root<TranslationValue> from = subquery.from(TranslationValue.class);
                subquery.distinct(true).
                    select(from).where(cb.and(
                    cb.equal(from.get(TranslationValue_.LOCALE).get(Locale_.VALUE), filterRequest.getLanguageCode())),
                    cb.equal(r.get(TranslationUnit_.ID), from.get(TranslationValue_.TRANSLATION_UNIT))
于 2018-08-23T15:57:27.503 回答