SQLIntegrityConstraintViolationException when running CacheLoadTest

2 messages Options
Embed this post
Permalink
Rohit Kelapure

SQLIntegrityConstraintViolationException when running CacheLoadTest

Reply Threaded More More options
Print post
Permalink
Dear All,

When executing the openJPA 2.0, org.apache.openjpa.persistence.datacache.CacheLoadTest, the tester thread encounters the following exceptions during insert operations ....

java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL091019011222610' defined on 'OPENJPA_SEQUENCE_TABLE'.

org.apache.openjpa.util.ObjectExistsException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL091019011222610' defined on 'OPENJPA_SEQUENCE_TABLE'.

org.apache.openjpa.persistence.EntityExistsException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL091019011222610' defined on 'OPENJPA_SEQUENCE_TABLE'.


Is there a way to avoid these exceptions during the transaction commit i.e. can I check for SQLIntegrityConstraint before ending the transaction.


Code for insert:

    private void insert()
        throws Exception {

        EntityManager em = emf.createEntityManager();
        startTx(em);

        for (int i = 0; i < (rnd(100)); i++) {
            em.persist(randomizeBean(rndclass().newInstance()));
        }

        endTx(em);
        endEm(em);
    }

--Thanks,
Rohit Kelapure


Miłosz Tylenda

Re: SQLIntegrityConstraintViolationException when running CacheLoadTest

Reply Threaded More More options
Print post
Permalink
Rohit,

If what you want is to receive an exception earlier, you could try calling EntityManager.flush() after persist(). Just make sure your unique constraints in the database are not deferred constraints.

Cheers,
Milosz

>
> Dear All,
>
> When executing the openJPA 2.0,
> org.apache.openjpa.persistence.datacache.CacheLoadTest, the tester thread
> encounters the following exceptions during insert operations ....
>
> java.sql.SQLIntegrityConstraintViolationException: The statement was aborted
> because it would have caused a duplicate key value in a unique or primary
> key constraint or unique index identified by 'SQL091019011222610' defined on
> 'OPENJPA_SEQUENCE_TABLE'.
>
> org.apache.openjpa.util.ObjectExistsException: The statement was aborted
> because it would have caused a duplicate key value in a unique or primary
> key constraint or unique index identified by 'SQL091019011222610' defined on
> 'OPENJPA_SEQUENCE_TABLE'.
>
> org.apache.openjpa.persistence.EntityExistsException: The statement was
> aborted because it would have caused a duplicate key value in a unique or
> primary key constraint or unique index identified by 'SQL091019011222610'
> defined on 'OPENJPA_SEQUENCE_TABLE'.
>
>
> Is there a way to avoid these exceptions during the transaction commit i.e.
> can I check for SQLIntegrityConstraint before ending the transaction.
>
>
> Code for insert:
>
>     private void insert()
>         throws Exception {
>
>         EntityManager em = emf.createEntityManager();
>         startTx(em);
>
>         for (int i = 0; i < (rnd(100)); i++) {
>             em.persist(randomizeBean(rndclass().newInstance()));
>         }
>
>         endTx(em);
>         endEm(em);
>     }
>
> --Thanks,
> Rohit Kelapure
>
>
>
> --
> View this message in context: http://n2.nabble.com/SQLIntegrityConstraintViolationException-when-running-CacheLoadTest-tp3858228p3858228.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>