Here is the stack trace. I am able to obtain the SQLState and
ErrorCode from the ReportingSQLException (which extends SQLException).
<0.9.7-incubating fatal store error>
org.apache.openjpa.persistence.RollbackException: The transaction has
been rolled back. See the nested exceptions for details on the errors
that occurred.
at
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:420)
at ex4.ShapeHelper.main(ShapeHelper.java:40)
Caused by: <0.9.7-incubating fatal general error>
org.apache.openjpa.persistence.PersistenceException: The transaction
has been rolled back. See the nested exceptions for details on the
errors that occurred.
at
org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2118)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1965)
at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1863)
at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1781)
at
org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:80)
at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1311)
at
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:866)
at
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:409)
... 1 more
Caused by: <0.9.7-incubating nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: Violation of
unique index: U_SHAPE_1 in statement [INSERT INTO SHAPE (NAME, TYPES)
VALUES (?, ?)] {prepstmnt 12213211 INSERT INTO SHAPE (NAME, TYPES)
VALUES (?, ?) [params=(String) MyShape, (String) [CIRCLE, SQUARE,
TRIANGLE]]} [code=-9, state=23000]
FailedObject: [EMAIL PROTECTED]
at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:3782)
at
org.apache.openjpa.jdbc.sql.HSQLDictionary.newStoreException(HSQLDictionary.java:308)
at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:97)
at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:67)
at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:106)
at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:71)
at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryRow(OperationOrderUpdateManager.java:203)
at
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush(OperationOrderUpdateManager.java:89)
at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514)
at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
... 8 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException:
Violation of unique index: U_SHAPE_1 in statement [INSERT INTO SHAPE
(NAME, TYPES) VALUES (?, ?)] {prepstmnt 12213211 INSERT INTO SHAPE
(NAME, TYPES) VALUES (?, ?) [params=(String) MyShape, (String)
[CIRCLE, SQUARE, TRIANGLE]]} [code=-9, state=23000]
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:191)
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$800(LoggingConnectionDecorator.java:56)
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:857)
at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1363)
at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:95)
... 15 more
On 8/21/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
> Hmm. Do they get converted, or wrapped? If it's a complete conversion,
> then we should do something to maintain that information, such as a
> subtype of one of the PersistenceExceptions.
>
> Can you post the full stack trace that you're seeing?
>
> -Patrick
>
> On 8/21/07, Christian Defoy <[EMAIL PROTECTED]> wrote:
> > Patrick,
> >
> > When I step into the code, I do see ReferentialIntegrityException
> > being created but they get converted to PersistenceException at some
> > point in PersistenceExceptions.translateStoreException(). My guess is
> > that no equivalent exception exists in the JPA spec...
> >
> > I also only look for SQLState 23000. I have nothing special to add to
> > that list...
> >
> > Thanks!
> >
> > Christian
> >
> > On 8/21/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
> > > When we can, we try to wrap such exceptions in a
> > > ReferentialIntegrityException. I think that we just look for SQLState
> > > of 23000 currently, though.
> > >
> > > Can you post stacks that correspond to codes that we should also be
> > > catching?
> > >
> > > -Patrick
> > >
> > > On 8/21/07, Christian Defoy <[EMAIL PROTECTED]> wrote:
> > > > Hello,
> > > >
> > > > I am looking for a way of programatically detecting whether an
> > > > exception was caused by a constraint violation. What is the best way
> > > > to do that?
> > > >
> > > > The only way I have found so far is to navigate up the cause chain of
> > > > the exception and see if one happens to be an SQLException and if so,
> > > > get the SQLState and see if it is 23xxx.
> > > >
> > > > Is there a simpler way?
> > > >
> > > > Oh, by the way, example 12.2 of the manual states that we can put
> > > > @Unique annotations in the @Table one but it turns out that type must
> > > > be @UniqueConstraint.
> > > >
> > > > Thanks in advance!
> > > >
> > > > Christian
> > > >
> > >
> > >
> > > --
> > > Patrick Linskey
> > > 202 669 5907
> > >
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>