I\'m getting this error from my EntityManager when I call the refresh function.
public void saveProduct(Product product) {
entityManager.refresh(product);
}
From the docs of EntityManager:
IllegalArgumentException - if not an entity or entity is not managed
@Entity
, or with .xml
configuration)merge()
it first, and then refresh()
it.public void saveProduct(Product product) {
...
Product managedProductEntity = entityManager.find(Product.class, product.getId());
entityManager.refresh(managedProductEntity);
...
}
Works this way. managedProductEntity
will be managed, and therefore it can be refreshed from database.