Using JPA (OpenJPA) in a J2SE application, I am trying to update the table with the contents of a list of records: adding new records or replacing existing records with what is in the list, if they exist.
1) What is the best approach for this?
To do this, I would like to perform several hundred merges within the same transaction ... (some of the entries in the list may be indentical with the same identifier)
It seems to work fine when using HSQLDB, but when using MySQL as the database, I get this exception: org.apache.openjpa.persistence.EntityExistsException: Duplicate entry
2) any idea why?
The code is simple and something like this:
EntityManager em = emfactory.createEntityManager(); em.getTransaction().begin(); // update messages for (Message msg : messages) { Entry e=new Entry(msg.getId(), msg.getText(),msg.getDate()); em.merge(e); } em.getTransaction().commit(); em.close();
thanks
source share