Hi there!
I have an entity that have a 1.N collection that has the follow cascade option:
Code:
@OneToMany(cascade = { CascadeType.PERSIST,
CascadeType.MERGE,
CascadeType.REMOVE },
mappedBy = "imovelHabitacional")
private List<Images> images = new ArrayList<Images>();
On the servlet, the entities are treat has detached entities, and to persist and update i do this
Code:
EntityManagerFactory emf = HibernateUtil.getEntityManagerFactory();
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.merge(imovelHabitacional);
tx.commit();
em.close();
every thing works fine on the creation of the "imovelHabitacional" entity. If i change that new entity, by adding an image to the "images" list, that new image is added to the DB by an insert, and the main entity is updated too. But when i remove an image from that list, nothing is done. That image still on the DB.
Does anyone know what am i doing (or not doing) wrong?
Thanks a lot!
--ms