You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by sjewett <sj...@clarksna.com> on 2009/05/12 22:57:51 UTC
Identify the record that caused unique constraint violation
Hi All,
We are using iBATIS 2.1.7. I'm getting a java.sql.BatchUpdateException:
ORA-00001: unique constraint when using executeBatch to insert records. I
would like to get some information (field values) about the specific record
that caused the unique constraint violation.
I read in the iBATIS documentation that with version 2.2.0 there is an
executeBatchDetailed method. The documents says that "If a
java.sql.BatchUpdateException occurs, the method will throw BatchException
which contains information about the statement that caused the exception . .
."
Does anyone know if this means I can identify the record that caused the
violation? Or if there is another way to get this information when using
batch inserts?
Any help is appreciated.
Thank you,
sjewett
--
View this message in context: http://www.nabble.com/Identify-the-record-that-caused-unique-constraint-violation-tp23510359p23510359.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Re: Identify the record that caused unique constraint violation
Posted by Nicholoz Koka Kiknadze <ki...@gmail.com>.
It may be database dependent. Here's extract from oracle docs
http://download.oracle.com/docs/cd/B10501_01/java.920/a96654/oraperf.htm
After a batch exception, the update counts array can be retrieved using the
getUpdateCounts() method of the BatchUpdateException object. This returns an
int array of update counts, just as the executeBatch() method does. In the
Oracle implementation of standard update batching, contents of the update
counts array are as follows after a batch exception:
- For a prepared statement batch, it is not possible to know which
operation failed. The array has one element for each operation in the batch,
and each element has a value of -3. According to the JDBC 2.0 specification,
a value of -3 indicates that an operation did not complete successfully. In
this case, it was presumably just one operation that actually failed, but
because the JDBC driver does not know which operation that was, it labels
all the batched operations as failures.
You should always perform a ROLLBACK operation in this situation.
Re: Identify the record that caused unique constraint violation
Posted by sjewett <sj...@clarksna.com>.
dm3 -
Thank you. I'll try that. I have a related question: Is there a way to
invoke the executeBatch() for the inserts and have iBATIS simply skip the
record that gets the unique constraint violation, and keep going?
Thanks again.
-sjewett
dm3 wrote:
>
> Well, you can try logging `java.sql.*` if you're not already doing it. The
> last statement before error should be what you're looking for.
>
> On Tue, May 12, 2009 at 11:57 PM, sjewett <sj...@clarksna.com> wrote:
>
>>
>> Hi All,
>>
>> We are using iBATIS 2.1.7. I'm getting a java.sql.BatchUpdateException:
>> ORA-00001: unique constraint when using executeBatch to insert records.
>> I
>> would like to get some information (field values) about the specific
>> record
>> that caused the unique constraint violation.
>>
>> I read in the iBATIS documentation that with version 2.2.0 there is an
>> executeBatchDetailed method. The documents says that "If a
>> java.sql.BatchUpdateException occurs, the method will throw
>> BatchException
>> which contains information about the statement that caused the exception
>> .
>> .
>> ."
>>
>> Does anyone know if this means I can identify the record that caused the
>> violation? Or if there is another way to get this information when using
>> batch inserts?
>>
>> Any help is appreciated.
>>
>> Thank you,
>> sjewett
>> --
>> View this message in context:
>> http://www.nabble.com/Identify-the-record-that-caused-unique-constraint-violation-tp23510359p23510359.html
>> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Identify-the-record-that-caused-unique-constraint-violation-tp23510359p23521134.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
Re: Identify the record that caused unique constraint violation
Posted by Vadim <de...@gmail.com>.
Well, you can try logging `java.sql.*` if you're not already doing it. The
last statement before error should be what you're looking for.
On Tue, May 12, 2009 at 11:57 PM, sjewett <sj...@clarksna.com> wrote:
>
> Hi All,
>
> We are using iBATIS 2.1.7. I'm getting a java.sql.BatchUpdateException:
> ORA-00001: unique constraint when using executeBatch to insert records. I
> would like to get some information (field values) about the specific record
> that caused the unique constraint violation.
>
> I read in the iBATIS documentation that with version 2.2.0 there is an
> executeBatchDetailed method. The documents says that "If a
> java.sql.BatchUpdateException occurs, the method will throw BatchException
> which contains information about the statement that caused the exception .
> .
> ."
>
> Does anyone know if this means I can identify the record that caused the
> violation? Or if there is another way to get this information when using
> batch inserts?
>
> Any help is appreciated.
>
> Thank you,
> sjewett
> --
> View this message in context:
> http://www.nabble.com/Identify-the-record-that-caused-unique-constraint-violation-tp23510359p23510359.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>