Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jpa] Do not log failure to persist item with duplicate timestamp as error #15978

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Set;

import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
Expand Down Expand Up @@ -164,7 +165,13 @@ public void store(Item item, @Nullable String alias) {
em.getTransaction().commit();
logger.debug("Persisting item...done");
} catch (Exception e) {
logger.error("Error while persisting item! Rolling back!", e);
if (e.getCause() instanceof EntityExistsException) {
// there's a UNIQUE constraint in the database, and we tried to write
// a duplicate timestamp. Just ignore
ccutrer marked this conversation as resolved.
Show resolved Hide resolved
logger.debug("Skipping persistence of item... it already exists");
ccutrer marked this conversation as resolved.
Show resolved Hide resolved
} else {
logger.error("Error while persisting item! Rolling back!", e);
}
em.getTransaction().rollback();
} finally {
em.close();
Expand Down