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);
}
}
}
Use setParameter(String name, Object value)
To make it better, use TypedQuery