update insert raw query JPA code example
Example: update insert raw query JPA
@Transactional
public void updateActiveStatus(String criteriaId) {
String updateQuery = "update table_name set status = false where criteria_id = :criteriaId ";
EntityManager em = emf.createEntityManager();
try {
em.joinTransaction();
Query q = em.createNativeQuery(updateQuery).setParameter( "criteriaId", criteriaId );
q.executeUpdate();
}finally{
em.close();
}
}
//adding transation is neccesary in delete/update queries.