gpt4 book ai didi

jpa-2.0 - JPA 2 无显式选择且隐式一冷未确定

转载 作者:太空宇宙 更新时间:2023-11-04 13:31:56 26 4
gpt4 key购买 nike

我正在尝试获取某个文件夹中的所有用户,该用户是在特定日期之后创建的。用户和文件夹之间的关系位于单独的表中。

这是我提出的查询,但它引发了异常

No explicit selection and an implicit one cold not be determined

代码

@Override
public List<RetailPostUserTbl> getNewUsersForSiteSince( Date date, Integer siteId )
{
List<RetailPostUserTbl> toReturn = new ArrayList<RetailPostUserTbl>();
EntityManager em = getEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();

Class<RpUserFolderMapTbl> userFolderPC = userFolderMapDAO.getPersistentClass();

CriteriaQuery<RpUserFolderMapTbl> mapQuery = cb.createQuery( userFolderPC );
Root<RpUserFolderMapTbl> root = mapQuery.from( userFolderPC );
Path<Integer> folderIdPath = root.get( RpUserFolderMapTbl_.folder ).get( FolderTbl_.folderId );

Predicate folderCondition = cb.equal( folderIdPath, siteId );

Subquery<RetailPostUserTbl> rpSubQ = mapQuery.subquery( persistentClass );
Root<RetailPostUserTbl> subQRoot = rpSubQ.from( persistentClass );
Path<UserTbl> userPath = subQRoot.get( RetailPostUserTbl_.user );
Path<Date> userCreatedPath = userPath.get( UserTbl_.userCreateDate );
Predicate userCreateDateCondition = cb.greaterThanOrEqualTo( userCreatedPath, date );
rpSubQ.where( userCreateDateCondition );

mapQuery.where( cb.and( folderCondition, cb.exists( rpSubQ ) ) );

TypedQuery<RpUserFolderMapTbl> query = em.createQuery( mapQuery );
List<RpUserFolderMapTbl> results = query.getResultList();
for ( RpUserFolderMapTbl result : results )
{
RetailPostUserTbl rpuser = result.getUser().getRetailPostUser();
toReturn.add( rpuser );
}
return toReturn;
}

有人知道为什么这不起作用吗?

最佳答案

您还应该为“子查询”设置显式选择。

rpSubQ.select(subQRoot);

关于jpa-2.0 - JPA 2 无显式选择且隐式一冷未确定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32090139/

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