openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <>
Subject RE: Cascade and persist issues
Date Thu, 01 Oct 2009 15:55:55 GMT
A lot of those error messages don't make any sense to me either. Try
cleaning your project, if I change the cascade types on fields Eclipse
doesn't seem to pick it up. Doing a clean then rebuild fixes the issue.


-----Original Message-----
From: ljnelson [] 
Sent: Friday, 2 October 2009 1:45 AM
Subject: Re: Cascade and persist issues

Yes, I guess my point is: I am cascading the relationship with a CascadeType
of ALL, but OpenJPA is telling me that I need to mark it as CascadeType.ALL, is.

On Thu, Oct 1, 2009 at 11:01 AM, crispyoz (via Nabble) <<ml-user%2B243560-833017765@n2.nabble.
> wrote:

> I do something similar, I have a user and a user has a single address so I
> use like this:
> User:
> Private String name;
> @OneToOne cascade={CascadeType.ALL})
> Private Address address;
> ....
> ...
> I construct the user, construct the address, link the address to the user
> and just use persist on the user which causes the address to be persisted
> due to the cascade type. I do the same thing with users that may share the
> same address, just the relationship is changed to
> @ManyToOne cascade={CascadeType.ALL})
> Chris
> -----Original Message-----
> From: Laird Nelson [mailto:[hidden
> Sent: Friday, 2 October 2009 12:33 AM
> To: [hidden
> Subject: Cascade and persist issues
> On a field marked @OneToMany(/*...*/ cascade = CascadeType.ALL), I am
> getting this error at persist() time:
> <openjpa-1.3.0-SNAPSHOT-r422266:820051 nonfatal user error>
> org.apache.openjpa.persistence.ArgumentException: Encountered new object
> persistent field "<key:class
>$ID>" during attach.  However,
> field does not allow cascade attach. Set the cascade attribute for this
> field to CascadeType.MERGE or CascadeType.ALL (JPA annotations) or "merge"
> or "all" (JPA orm.xml). You cannot attach a reference to a new object
> without cascading.
> I am following the advice of in
> terms of structure.
> To be specific, I have a Party identified with an autogenerated int PK
> a @OneToMany relationship with a PartyPostalAddressBinding, which has a
> @ManyToOne relationship with a PostalAddress.  A PostalAddress, in turn,
> owned by exactly one Party.
> In my test case, I persist the Party (then I have to flush(), which is
> tremendously irritating) yielding, let's say, party1.  Then I create a new
> PostalAddress and assign party1 as its owner.  I persist that (and again
> have to flush() in order to avoid errors--no idea why), yielding
> postalAddress1.  Finally, I insert a new binding that links party1 and
> postalAddress1 into party1's Map of bindings.  I then merge() party1
> I don't think I should have to do).  It is at this point that OpenJPA
> me that my @OneToMany field, with cascade markings all over it, needs to
> be,
> um, marked with CascadeType.ALL, which it is.
> I am quite happy to attach all of this, but wanted to see if I'm doing
> something obviously stupid first.
> Thanks,
> Laird
> ------------------------------
>  View message @
> To start a new topic under OpenJPA Users, email
> To unsubscribe from OpenJPA Users, click here< (link removed) =>.

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message