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 in persistent field "blox.party.jpa.PartyEntity.postalAddresses<key:class blox.party.jpa.PartyPostalAddressBinding$ID>" during attach. However, this 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 http://www.screaming-penguin.com/node/7513 in terms of structure. To be specific, I have a Party identified with an autogenerated int PK with a @OneToMany relationship with a PartyPostalAddressBinding, which has a @ManyToOne relationship with a PostalAddress. A PostalAddress, in turn, is 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 (which I don't think I should have to do). It is at this point that OpenJPA tells 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