persistence@glassfish.java.net

FYI: Re: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST.

From: Markus Fuchs <Markus.Fuchs_at_Sun.COM>
Date: Thu, 25 Jan 2007 11:12:27 -0800

Hi Jon, all,

I was investigating the same IllegalStateException in a different
situation. The issue here was that the persistence context was re-used
for further transactions after the execution of bulk operations (bulk
update/bulk deletes). As bulk operations aren't synchronized with the
persistence context (see JPA spec 4.10), the persistence context should
be closed after the corresponding transaction commits.

Thanks,

-- markus.

Jon Miller wrote:
> Thanks again Mitesh. I seem to have been able to correct the original
> problem that I had. The weird thing is that the object in question was
> the object that I was passing to EntityManager.merge() itself. I think
> what was happening was that there was another object that was already
> in the cache which referenced this object and I think it was
> processing that object first rather than the object that I passed in
> directly. I fixed it by adding cascade={CascadeType.MERGE,
> CascadeType.PERSIST, CascadeType.REFRESH} to a few relationships that
> I have.
>
> Thanks for making that change, it's definitely helpful.
>
> Jon
>
> ----- Original Message ----- From: "Mitesh Meswani"
> <Mitesh.Meswani_at_Sun.COM>
> To: <persistence_at_glassfish.dev.java.net>
> Sent: Friday, January 12, 2007 1:31 PM
> Subject: Re: java.lang.IllegalStateException: During synchronization a
> new object was found through a relationship that was not marked
> cascade PERSIST.
>
>
>> I think the jars are packed using jar packager. Since a promoted
>> persistence build is also out, another option is to get persistence
>> only build from here
>> <https://glassfish.dev.java.net/downloads/persistence/JavaPersistence.html>
>>
>>
>> -Mitesh
>>
>> Jon Miller wrote:
>>> OK, I downloaded the binary for B31 which came out on the 11th. The
>>> problem now is that the jar file is a
>>> toplink-essentials.jar.pack.gz. I gunziped it, but, I don't know
>>> what to do with it after that. Is it really necessary to compress a
>>> file that is already compressed? Seems a bit excessive.
>>>
>>> Jon
>>>
>>> ----- Original Message ----- From: "Mitesh Meswani"
>>> <Mitesh.Meswani_at_Sun.COM>
>>> To: <persistence_at_glassfish.dev.java.net>
>>> Sent: Thursday, January 11, 2007 12:53 PM
>>> Subject: Re: java.lang.IllegalStateException: During synchronization
>>> a new object was found through a relationship that was not marked
>>> cascade PERSIST.
>>>
>>>
>>>> Hi Jon,
>>>>
>>>> The fix should be in yesterday's nightly build of glassfish. Please
>>>> extract toplink-essentials.jar from it (the standalone persistence
>>>> bundle is only available for promoted builds).
>>>>
>>>> It should be very easy to build from sources also. Following
>>>> summarizes steps needed to just build entity-persistence module
>>>>
>>>> mkdir workspace
>>>> % cd workspace
>>>> % cvs -d :pserver:<userid>@cvs.dev.java.net:/cvs checkout
>>>> glassfish/bootstrap
>>>>
>>>>
>>>> #
>>>> #Configure Build Variables as described in the build quick start
>>>> guide step 2
>>>> # before proceeding further
>>>> #
>>>>
>>>> cd glassfish/bootstrap
>>>> #checkout sources
>>>> maven -Dmodules=entity-persistence checkout
>>>> #bootstrap glassfish environment
>>>> maven bootstrap
>>>> #build entity-persistence
>>>> maven -Dmodules=entity-persistence build
>>>> Regards,
>>>> Mitesh
>>>>
>>>>
>>>> Jon Miller wrote:
>>>> Mitesh,
>>>>
>>>> Thanks for the super fast enhancement on this. Much appreciated.
>>>> Are there nightly binary builds, or, do you have to build it from
>>>> the source? If the later, I'm wondering which projects I need to
>>>> check out. I tried building from the source once before, but, from
>>>> what I remember, I needed something more than just the persistence
>>>> project.
>>>>
>>>> Jon
>>>>
>>>> ----- Original Message ----- From: "Mitesh Meswani"
>>>> <Mitesh.Meswani_at_Sun.COM>
>>>> To: <persistence_at_glassfish.dev.java.net>
>>>> Sent: Wednesday, January 10, 2007 8:02 PM
>>>> Subject: Re: java.lang.IllegalStateException: During
>>>> synchronization a new object was found through a relationship that
>>>> was not marked cascade PERSIST.
>>>>
>>>>
>>>>
>>>> Hi Jon,
>>>>
>>>> A fix has been checked in
>>>> <https://glassfish.dev.java.net/source/browse/glassfish/entity-persistence/src/java/oracle/toplink/essentials/internal/localization/i18n/ExceptionLocalizationResource.java?r1=1.14&r2=1.15>.
>>>> The error message now includes the offending object. Today's
>>>> nightly should contain the fix. Typically you get into this
>>>> situation if you are not maintaining both sides of your
>>>> relationships. For example if you have a domain model with
>>>> Department and Employee with a bidirectional relationship, if you
>>>> do emp.setDepartment(newDepartment), you will need to make sure to
>>>> remove the employee from its old department's employees collection
>>>> and add it to newDeapartment's employee collection.
>>>>
>>>> -Mitesh
>>>>
>>>>
>>>> Jon Miller wrote:
>>>>
>>>> Hi all,
>>>>
>>>> I'm running into the following exception. I'm wondering if
>>>> anyone has suggestions on how to find the offending object? I'm
>>>> thinking it might be nice if the error message did something like
>>>> print the toString() representation of the offending object.
>>>>
>>>> Caused by: javax.faces.el.EvaluationException:
>>>> javax.persistence.RollbackException:
>>>> java.lang.IllegalStateException: During synchronization a new
>>>> object was found through a relationship that was not marked cascade
>>>> PERSIST.
>>>>
>>>> Jon
>>>>
>>>>
>>>>
>>