Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:19:01+00:00 2026-06-03T20:19:01+00:00

Referencing JPQL , it’s not clear to me exactly how to query a table.

  • 0

Referencing JPQL, it’s not clear to me exactly how to query a table.

What I want is, if it exists, the @Entity Note for a given messagId and group, but I don’t understand the syntax.

How do I specify the messageId and group for the below query?

public void persist(Msg message) {
    LOG.info("\t" + message);
    LOG.info("isOpen?" + em.isOpen());
    em.getTransaction().begin();
    int id = message.getId();
    Query q = em.createQuery("SELECT  n "
            + "FROM Notes n WHERE n.messageId = :messageId "
            + "AND n.group = :group");
    List results = q.getResultList();
    em.getTransaction().commit();
    for (Object o : results) {
        LOG.info("object is \n\n" + o);
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:19:04+00:00Added an answer on June 3, 2026 at 8:19 pm

    Use setParameter(String name, Object value)

    q.setParameter("messageId", id).setParameter("group", group);
    

    To make it better, use TypedQuery

    public void persist(Msg message) {
        LOG.info("\t" + message);
        LOG.info("isOpen?" + em.isOpen());
        em.getTransaction().begin();
        int id = message.getId();
        TypedQuery<Note> q = em.createQuery("SELECT  n "
                + "FROM Notes n WHERE n.messageId = :messageId "
                + "AND n.group = :group", Note.class);
        q.setParameter("messageId", id).setParameter("group", group);
        List<Note> results = q.getResultList();
        em.getTransaction().commit();
        for (Note o : results) {
            LOG.info("object is \n\n" + o);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a self referencing table and I want a mysql query that will
I have a standard self referencing table of Categories . In my entity model
Given a self referencing table Item ------------- Id (pk) ParentId (fk) With a related
I have a self referencing table named categories that has a parentcategoryid column that
I have a self-referencing table 'comments' where comments.replyToId REFERENCES comments.ID. My question is, how
I have a self-referencing table (Customers) and a table that will link to one
Does a Foreign Key referencing a Primary Key need the NOT NULL constraint in
Referencing this question: System.Reflection.Assembly.LoadFile Locks File System.IO.File.ReadAllBytes(path) wont work since it's not a standalone
I have one Table with a self referencing foreign key with DeleteAction set to
When referencing a method's address, should we take into account the overriding or not?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.