JPA无法找到命名参数

Bil*_*mus 4 java hibernate jpa

我不断收到以下错误:" 无法找到命名参数[articleCommentId] "但它对我没有意义,因为对我来说命名参数非常到位.

public ArticleCommentForDisplay getCommentByArticleCommentId(BigInteger articleCommentId) {

    String queryString = "select c.article_comment_id,  "
            + "       c.article_id,  "
            + "       c.parent_comment_id, "
            + "       p.nickname, "
            + "       c.title,  "
            + "       c.comment, "
            + "       c.person_id, "
            + "       c.confirmed_user, "
            + "       c.comment_depth, "
            + "       c.moderation_rank, "
            + "       c.moderation_reason, "
            + "       c.hide, "
            + "       c.hide_reason, "
            + "       c.session_id, "
            + "       c.confirmation_uuid, "
            + "       c.created_timestamp, "
            + "       c.created_by_id, "
            + "       c.updated_timestamp, "
            + "       c.updated_by_id, "
            + "       c.update_action, "
            + "       null as comment_path "
            + "from article_comment c "
            + "   join person p "
            + "       on p.person_id = c.person_id "
            + "where c.article_comment_id = :articleCommentId; ";

    Query query = em.createNativeQuery(queryString, "ArticleCommentMap");
    query.setParameter("articleCommentId", articleCommentId);

    List <ArticleCommentForDisplay> articleComments = new ArrayList<>();
    articleComments = query.getResultList();
    ArticleCommentForDisplay theComment = articleComments.get(0);

    return (theComment);

}
Run Code Online (Sandbox Code Playgroud)

以下是堆栈跟踪的摘录以及相关错误:

Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [articleCommentId]
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:379)
    at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:72)
    at com.extremelatitudesoftware.content.ArticleCommentFacade.getCommentByArticleCommentId(ArticleCommentFacade.java:293)
Run Code Online (Sandbox Code Playgroud)

Adr*_*hum 8

我打赌这是由于;您的查询字符串中的额外内容.

SQL/HQL不需要以分号结束


Zaw*_* oo 7

未在本机查询中定义命名参数JPA Specification.

更换

where c.article_comment_id = :articleCommentId;
Run Code Online (Sandbox Code Playgroud)

where c.article_comment_id = ?1;
....
query.setParameter(1, articleCommentId)
Run Code Online (Sandbox Code Playgroud)