Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,7 @@ public T persist(final T entity) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
String sql = null;
boolean committed = false;
try {
txn.start();
for (final Pair<String, Attribute[]> pair : _insertSqls) {
Expand Down Expand Up @@ -1673,6 +1674,7 @@ public T persist(final T entity) {
insertElementCollection(entity, _idAttributes.get(_table)[0], id, ecAttributes);
}
txn.commit();
committed = true;
} catch (final SQLException e) {
logger.error("DB Exception on: " + pstmt, e);
handleEntityExistsException(e);
Expand All @@ -1681,6 +1683,10 @@ public T persist(final T entity) {
throw new CloudRuntimeException("Problem with getting the ec attribute ", e);
} catch (IllegalAccessException e) {
throw new CloudRuntimeException("Problem with getting the ec attribute ", e);
} finally {
if (!committed) {
txn.rollback();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to just rollback in the exception handlers instead?

}
}

return _idField != null ? findByIdIncludingRemoved(id) : null;
Expand Down