[Pljava-dev] Savepoints and continuing from SQLExceptions [snapshot reference 0x19a1710 is not owned by resource owner TopTransaction]

From: hal(dot)hildebrand at me(dot)com (Hal Hildebrand)
To:
Subject: [Pljava-dev] Savepoints and continuing from SQLExceptions [snapshot reference 0x19a1710 is not owned by resource owner TopTransaction]
Date: 2012-10-18 01:28:49
Message-ID: 96DBE277-8790-4B4A-A120-0408D97D8464@me.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

So this problem has been driving me nuts and I think I've finally exhausted my googling abilities in searching for the answer.

The issue is that I'd like to recover from a SQLException, roll back the savepoint and then issue another query and then reissue the failing query. The catch works, I roll back the save point, issue the additional query. However, when I retry the original query, I get the error:

Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException:
ERROR: snapshot reference 0x19a1710 is not owned by resource owner TopTransaction

I'm sure that I am doing something wrong here, as this is the first time I'm trying to use savepoints in this way and I'm doing it inside a PL/Java function...

Anyways, the code is below. The error above occurs at the last "query.execute();" in the code below.

Any help would be appreciated.... Hopefully, I'm just missing something basic and it's an easy fix....

-Hal

Code:
____________________

public void addId(Long value, String key) throws SQLException {
String tempTableName = SHARED_TEMP + key;
PreparedStatement query = connection.prepareStatement(String.format("INSERT INTO %s VALUES (?)",
tempTableName));
query.setLong(1, value);
Savepoint savepoint = connection.setSavepoint();
try {
query.execute();
} catch (SQLIntegrityConstraintViolationException e) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, String.format("table %s already has %s",
tempTableName, value));
}
} catch (SQLException e) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO,
String.format("Creating table %s", tempTableName), e);
}
query.close();
connection.rollback(savepoint);

PreparedStatement create = connection.prepareStatement(String.format("CREATE TEMPORARY TABLE %s (id BIGINT PRIMARY KEY) ON COMMIT DROP",
tempTableName));
try {
create.execute();
} finally {
create.close();
}
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO,
String.format("Retrying insert of %s into %s", value,
tempTableName), e);
}
query = connection.prepareStatement(String.format("INSERT INTO %s VALUES (?)",
tempTableName));
query.setLong(1, value);
query.execute();
} finally {
query.close();
connection.releaseSavepoint(savepoint);
}
}

Browse pljava-dev by date

  From Date Subject
Next Message Nalamothu, Bhaskar 2012-10-22 14:11:04 [Pljava-dev] help :pljava sqlj.install_jar('path', 'jarname', true) running infinitely
Previous Message bruno 2012-10-17 17:21:22 [Pljava-dev] érreur appel de procédure pl/java