JPA Hybrid Query Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...... | |
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