Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created May 16, 2016 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/59cad3ac629f4a1225084504cc79009b to your computer and use it in GitHub Desktop.
Save abhirockzz/59cad3ac629f4a1225084504cc79009b to your computer and use it in GitHub Desktop.
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