Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JPA Hybrid Query Example
......
private static final String FIND_ASSIGNEE = "SELECT a.assignee FROM Approvals a WHERE a.id = :reqId";
@PersistenceContext(unitName="AccessRequestDataStore")
private EntityManager em;
public void test(String reqId) {
//create once and bind
Query query = em.createQuery(FIND_ASSIGNEE);
em.getEntityManagerFactory().addNamedQuery("findAssignee", query);
//use it
String assignee = em.createNamedQuery("findAssignee")
.setParameter("reqId", reqId)
.getSingleResult();
}
......
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment