Kako koristiti JPA named query sa Spring JpaTemplate-om

Započeo maxogm, 27.12.2010, 00:05

prethodna tema - sledeća tema

maxogm

Koristite JpaCallback da biste izvrsili vas JPA Named query:


@Transactional
public Integer removeAuthor(Book book){
final Book b = book;
Integer k = template.execute(new JpaCallback<Integer>() {
public Integer doInJpa(EntityManager em) throws PersistenceException {
return em.createNamedQuery("Book.updateAuthor")
.setParameter(1, null)
.setParameter(2, b.getId())
.executeUpdate();
}
}, true);
return k;
}