[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] During synchronization a new object was found through a relationship that was not marked cascade PERSIST:
|
Hello Tom,
Especially the SojournPosition is also referenced by the TourPosition and that relation is not marked cascade=PERSIST.
Does this mean when I want an instance (e.g. of SojournPosition) to be persisted without explicitly calling persist(), I must mark it cascade=PERSIST in any relation it is part of?
- Michael
-----Ursprüngliche Nachricht-----
Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] Im Auftrag von Tom Ware
Gesendet: Mittwoch, 7. September 2011 17:54
An: EclipseLink User Discussions
Betreff: Re: [eclipselink-users] During synchronization a new object was found through a relationship that was not marked cascade PERSIST:
'hard to tell from what you have provided.
The mappings you haven't included, could easily be causing this issue. How are
your classes becoming managed? Are there other non-cascaded mappings on any of
the objects being persisted? Are they referencing elements that are causing the
problem? (i.e. Do both Sojourn and SojournPosition have no other relationships)
-Tom
Michael Simons wrote:
> Hello Tom,
>
> AFAIK it is that simple:
>
> class Sojourn {
> // ...
>
> /** Set of sorted references to tour-stops that take place at this sojourn. Please remind that these are also part of a tour. */
> @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.DETACH, CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.MERGE}, fetch = FetchType.LAZY, mappedBy = "sojourn")
> @JoinFetch(value=JoinFetchType.OUTER)
> private Set<SojournPosition> positions;
>
> /**
> * Creates a SojournPosition that references the given TourPosition and inserts it to the set of psoitions.
> */
> public SojournPosition addTourPosition (int index, TourPosition s) {
> if (index < 0)
> throw new IllegalArgumentException (String.format ("Value %d for index is too small.", index));
> List<SojournPosition> sorted = getPositionsBySeq ();
> if (index > sorted.size ())
> throw new IllegalArgumentException (String.format ("Value %d for index is too big.", index));
> if (index == sorted.size ()) {
> if (positions == null) positions = new HashSet<SojournPosition>();
> SojournPosition sp = new SojournPosition (this, s, index);
> positions.add (sp);
> return sp;
> } else {
> SojournPosition sp = new SojournPosition (this, s, index);
> List<SojournPosition> positions = getPositionsBySeq();
> for(int i = index; i < positions.size(); i++){
> SojournPosition tempPos = positions.get(i);
> tempPos.setIndex(tempPos.getIndex() + 1);
> }
> positions.add (sp);
> return sp;
> }
> }
> }
>
> class SojournPosition {
> // ...
> @ManyToOne(fetch=FetchType.LAZY)
> @JoinColumn(name="sojourn_id", nullable=false)
> @ForeignKey(onDelete=ForeignKeyType.CASCADE, onUpdate=ForeignKeyType.RESTRICT) // That's an annotation of our own.
> private Sojourn sojourn;
> }
>
> - Michael
>
> -----Ursprüngliche Nachricht-----
> Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] Im Auftrag von Tom Ware
> Gesendet: Mittwoch, 7. September 2011 17:20
> An: EclipseLink User Discussions
> Betreff: Re: [eclipselink-users] During synchronization a new object was found through a relationship that was not marked cascade PERSIST:
>
> You are correct (the key here is the lack of a cascade to a related object). Is
> your failing example that simple?
>
> -Tom
>
> Michael Simons wrote:
>> Hello Tom,
>>
>> but isn't that what CascadeType.PERSIST is mentioned to do?
>> In the example given: If the instance of B referenced in A was marked cascade=CascadeType.PERSIST in A. Then I expect that this instance of B is persisted by EL, without a extra call of em.persist().
>> Am I wrong?
>>
>> -Michael
>>
>> -----Ursprüngliche Nachricht-----
>> Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] Im Auftrag von Tom Ware
>> Gesendet: Mittwoch, 7. September 2011 17:11
>> An: EclipseLink User Discussions
>> Betreff: Re: [eclipselink-users] During synchronization a new object was found through a relationship that was not marked cascade PERSIST:
>>
>> This exception indicates that there is a non-managed object related to an object
>> that is managed.
>>
>> e.g. You have a relationship between A and B without cascade persist. You
>> create an A, related it to a B and then persist the A without persisting the B.
>>
>> -Tom
>>
>> Michael Simons wrote:
>>> Hello,
>>>
>>>
>>>
>>> I've got the exception mentioned in the subject although the relation is
>>> marked cascade PERSIST.
>>>
>>> Any ideas what might cause this?
>>>
>>> Is this a known bug?
>>>
>>>
>>>
>>> We're using EL 2.1.3
>>>
>>>
>>>
>>> Kind Regards,
>>>
>>> Michael Simons
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users