javax.persistence.RollbackException: Transaction marked as rollbackOnly
Hi,
I have raw data to be processing.
(1) read each record in the raw data table, and parser them, insert the result into another table, then remove this record from raw data table
(2) if there are exception when insert a bad format, then try to remove this record from raw data table cause the error:
javax.persistence.RollbackException: Transaction marked as rollbackOnly
my code using JPA like this:
while (true) {
RawGpsData raw = findOneGPSLogsRawData();
if(raw != null) {
try{
if(processRawData(raw) {
getEntityManager().getTransaction().begin();
getEntityManager().persist(dataAudiTrail);
getEntityManager().remove(raw);
getEntityManager().getTransaction().commit();
getEntityManager().clear();
}
} catch (RuntimeException re) {
getEntityManager().getTransaction().begin();
getEntityManager().remove(raw);
getEntityManager().getTransaction().commit();
}
}
Can someone help me with this issue?
Thanks