Monday, May 11, 2009

Writing a Parameterized SQL Query in EJB 3.0

protected EntityManager manager;
...
String ejbqlDelete = "delete from ClientTicket p where " +
"p.closed = :paramClosed and " +
"p.department = :paramDepartment and " +
"p.ticketUserID = :paramTicketUserID and " +
"p.ticketName = :paramTicketName";

int deletedEntities = manager.createQuery(ejbqlDelete).
setParameter("paramClosed", Boolean.TRUE).
setParameter( "paramDepartment", adminid).
setParameter( "paramTicketUserID", userID ).
setParameter( "paramTicketName", delTicket ).
executeUpdate();

No comments:

Post a Comment