0

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));
   }
oxyt
  • 1,816
  • 3
  • 23
  • 33
  • 1
    Is the question you linked really similar to yours? There the OP asks to get _all_ entities via the entity manager while you want to remove products. Besides that, did you try it? What would you expect `remove(entity)` to do if not cause the entity manager to remove the entity from the database? – Thomas Sep 07 '18 at 15:23

1 Answers1

1

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

maio290
  • 6,440
  • 1
  • 21
  • 38