Skip to content
Advertisement

JPA could not locate named parameter

I keep getting the following error: “could not locate named parameter [articleCommentId]” but it doesn’t make sense to me because to me the named parameter is very much in place.

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

}

Here is an extract of the stack trace with the relevant error:

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)

Advertisement

Answer

I bet it is due to the extra ; in your query string.

SQL/HQL does not need to be terminated by semicolon

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement