8

「名前付きパラメーター [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);

}

関連するエラーを含むスタック トレースの抜粋を次に示します。

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)
4

6 に答える 6

23

;クエリ文字列の余分な部分が原因だと思います。

SQL/HQL はセミコロンで終了する必要はありません

于 2012-11-15T04:07:39.540 に答える
7

名前付きパラメータは、 のネイティブ クエリに対して定義されていませんJPA Specification

交換

where c.article_comment_id = :articleCommentId;

where c.article_comment_id = ?1;
....
query.setParameter(1, articleCommentId)
于 2012-11-15T06:03:13.603 に答える
0

クエリの最後で名前付きパラメーターを使用している場合は、; を削除します。あなたのクエリから

于 2020-04-06T06:55:06.543 に答える