Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Problem after trying to insert a new object

Hi James,

i calles the EntityManager#clear() method now on the right place (immediately after the commit crashed) and no problem occurs. So i don't need to create a new instance of EntityManager.

Thanks for the help...

On Mon, Feb 9, 2009 at 5:47 PM, Rodrigue Lagoue <rlagoue@xxxxxxxxxxxxxx> wrote:
Hi James,

Thanks for the answer. I think i already tried to solve the problem by calling EntityManager#clear() without success. 

I will try to get a new instance of EntityManager tomorrow, if it works i will tell you.



On Mon, Feb 9, 2009 at 4:53 PM, James Sutherland <jamesssss@xxxxxxxxx> wrote:

If an error occurs, you cannot continue to use the same EntityManager.  You
should either get a new EntityManager, or call clear().  All objects managed
by the EntityManager will become detached, you should not continue to use
these objects.

JPA does not provide for error handling.  EclipseLink's native UnitOfWork
API does have some support for error handling using its
commitAndResumeOnFailure, revert, API's, but these are not currently exposed
through JPA.

bests


Rodrigue Lagoue Njinthe wrote:
>
> Hi all!
> i have a curious problem using eclipselink
>
> i have the following classes
>
> public class HealthProfessional {
>     private Institution institution;
> }
>
> public class Network {
>     private List<Institution> institutions;
> }
>
> public class Institution {
>   private List< HealthProfessional  > healthprofessionals;
> }
>
> NB: i remove the jpa annotations, but i can assure that they are correct.
>
> The problem:
>
> I use stored procedures (i configured it by implementing the
> DescriptorCustomizer interface) to write changes and new object to an
> oracle
> Database (10g), and read information from views.
>
> But by adding a new HealthProfessional there is an exception thrown from
> the
> database (the issue is being resolved by somebody else). Since i use a
> strongly tied domain model, i build all the  relations between the
> instances
> involved before saving. I catch the exception coming from the database and
> suppose the system would continue to work without problem.
>  - But the next time i tryied to refresh the corresponding network, i get
> an
> Exception from the EntityManager telling that the Network instance is no
> more managed.
>     - so i fixed by catching the exception and retrieve a new instance
> using
> EntityManager#find() method
>
> - by the next commit (another use cases) i find out that the old network
> instance is always somewher in the session, because eclipselink tries to
> insert it (as new object), although  the id is already setted on it.
>
> A possible solution could be to set eclipselink so that, it insert objects
> only if it was explicitely required (calling EntityManager#persist() or
> EntityManager#merge() methods). Is there a way to do it?
>
> if not, how can i solve the problem
>
> thanks for any help
>
> Rodrigu
>
>





Back to the top