I need some clarification on the right way to retry a "retryable" exception (e.g. something like lock wait timeout) when using java persistence. For example, with pseudocode like:
EntityTransaction tx = em.getTransaction();
tx.begin();
for (a bunch of objects) {
em.persist(object);
}
tx.commit();
I sometimes get an exception thrown at the em.persist call if there's a lock in the db. Can I just wrap that in a try/catch and retry it (with some count, obviously)? Or do I have to wrap the whole tx.begin/commit and redo that?
thx