openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plins...@gmail.com
Subject Re: EntityExistsException
Date Mon, 03 Dec 2007 23:30:14 GMT
Hi,

The posted stack trace looks fine to me. The duplicate record is being
detected while writing to the database during commit, and this is
causing the tx to fail, hence the RollbackException.

If you changed your test to load all the Messages into memory in the
tx before calling persist() then you would see the
EntityExistsException. In other words, OpenJPA will generally only
throw EntityExistsException on persist if it knows that there is a
duplicate. It will not go to the database to check before every
persist, as this would be slow. If you need that behavior, then you
can just call em.find() and throw an exception if the return val is
null.

-Patrick

On 12/3/07, Gul Onural <onural@nortel.com> wrote:
>
> Filed a JIRA for this issue :
> https://issues.apache.org/jira/browse/OPENJPA-458
>
> Gul
>
>
> -----Original Message-----
> From: Craig.Russell@Sun.COM [mailto:Craig.Russell@Sun.COM]
> Sent: Sunday, December 02, 2007 6:16 PM
> To: users@openjpa.apache.org
> Subject: Re: EntityExistsException
>
> Hi Gul,
>
> The way I read the spec, these exceptions should be the top exception.
> That is, you should be able to } catch (EntityExistsException eeex) {
> and not have to catch Throwable and dive into the exception.
>
> If this is not the behavior you see, please raise a JIRA and attach a
> simple test case. And if you're so inclined, provide a patch for the
> issue.
>
> Thanks,
>
> Craig
>
> On Dec 2, 2007, at 8:32 AM, Gul Onural wrote:
>
> >
> > The JPA Spec states defines five exceptions for JPA providers to
> > raise, see below. However, the OpenJPA buries these exceptions
> > undeterministic number of levels of nested exceptions, i.e. not
> > obvious how many times I need to catch throwable using ex.getCause().
> >
> > Am I missing something ? All I am trying to find out is that if the
> > transaction is rolled back because of the fact that the entity already
>
> > exists programmatically. Is there a way to deterministically find out
> > this programmatically, how many level deep I have to go to catch
> > standard JPA exceptions In OpenJPA?
> >
> > Gul
> >
> >
> > EntityExistsException : Thrown by the persistence provider when
> > EntityManager.persist(Object) is called and the entity already exists.
> > EntityNotFoundException : Thrown by the persistence provider when an
> > entity reference obtained by EntityManager.getReference
> > (Class,Object) is
> > accessed but the entity does not exist.
> > NonUniqueResultException : Thrown by the persistence provider when
> > getSingleResult() is executed on a query and there is more than one
> > result from the query.
> > NoResultException : Thrown by the persistence provider when
> > getSingleResult() is executed on a query and there is no result to
> > return.
> > OptimisticLockException : Thrown by the persistence provider when an
> > optimistic locking conflict occurs.
> > PersistenceException : Thrown by the persistence provider when a
> > problem occurs.
> > RollbackException : Thrown by the persistence provider when the
> > EntityTransaction.commit() fails.
> > TransactionRequiredException : Thrown by the persistence provider when
>
> > a transaction is required but is not active.
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp!
>
>


-- 
Patrick Linskey
202 669 5907

Mime
View raw message