gpt4 book ai didi

java - 将此 HQL 转换为条件

转载 作者:行者123 更新时间:2023-12-01 22:49:38 25 4
gpt4 key购买 nike

我有以下 HQL 语句:

select auditRecord from AuditRecordEntity auditRecord where auditRecord.auditAccount.accountId = :accountId

我想将其转换为使用 javax.persistence.criteria.CriteriaBuilder,但我不确定该怎么做,非常感谢任何帮助!

CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<Object> query = builder.createQuery();
Root<AuditRecordEntity> root = query.from(AuditRecordEntity.class);
// what next?

最佳答案

试试这个:

CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<AuditRecordEntity> criteriaQuery = criteriaBuilder.createQuery(AuditRecordEntity.class);
Root<AuditRecordEntity> root = criteriaQuery.from(AuditRecordEntity.class);

Predicate predicate = criteriaBuilder.equal(root.get("auditAccount").get("accountId"), accountId);
criteriaQuery.where(predicate);

TypedQuery<AuditRecordEntity> query = em.createQuery(criteriaQuery);

return query.getSingleResult();

关于java - 将此 HQL 转换为条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24907092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com