Reputation: 1854
I want to know if I can perform em.remove
for each element in that local list? Does this code changes state in DB?
TypedQuery<Product> query = em.createNamedQuery("Product.findByCode", Product.class);
query.setParameter("code", code);
List<Product> productList= query.getResultList();
for (int i = 1; i < productList.size(); i++) {
em.remove(productList.get(i));
}
Upvotes: 0
Views: 45
Reputation: 6742
Yes it changes the DB, since that is his job.
The EntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities.
https://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html
Upvotes: 1