Hi Enrico, Here is my example, and it runs fine: (1) EntityA.java:
@Entity public class EntityA { @Column(name="A_ID") @Id private int id; private String name; @OneToOne(fetch = FetchType.LAZY) @JoinColumns([EMAIL PROTECTED](name="B_ID", referencedColumnName="B_ID", insertable=false,updatable=false)}) private EntityB entityB; ... omit getters and setters } (2) EntityB: @Entity public class EntityB { @Column(name="B_ID") @Id private int id; private String name; ... omit getters and setters } (3) the test case: em.getTransaction().begin(); EntityA a = new EntityA(); a.setName("1"); a.setId(1); em.persist(a); em.getTransaction().commit(); Do you want to try my test case to see if it works? -f --- On Wed, 6/11/08, Enrico Goosen <[EMAIL PROTECTED]> wrote: > From: Enrico Goosen <[EMAIL PROTECTED]> > Subject: Re: How to PERSIST object without loading references? > To: users@openjpa.apache.org > Date: Wednesday, June 11, 2008, 11:44 AM > I'm getting so frustrated with OpenJPA! > I'm also experiencing the problem listed in previous > reply, and once again, > no response to that post. > Here's some code to explain my problem: > TblPdtbnf.java: > @OneToOne(fetch = FetchType.LAZY) > @JoinColumns([EMAIL PROTECTED](name > ="PDTBNF_ID",referencedColumnName="PDTBNF_ID",insertable=false,updatable=false)}) > > private TblPdtbnfcde tblPdtbnfcde; > > When I save a TblPdtbnf record, I get this error: > ERRORJun 11 20:30:12 Encountered new object > "[EMAIL PROTECTED]" > in persistent field > "za.co.metcapri.model.ebstatus.TblPdtbnf.tblPdtbnfcde" > of managed object > "[EMAIL PROTECTED]" > during attach. However, > this field does not allow cascade attach. You cannot > attach a reference to > a new object without cascading.; > > But I don't want to save the tblPdtbnfcde...didn't > I make that clear by > adding insertable=false!!! > > If I remove insertable=false, updatable=false...that > doesn't help either. > > Do I have to set that field to null to save this record? > There must be a better way. > > Is there anybody out there that knows the solution??? > > > Anonimus wrote: > > > > > > Ognjen Blagojevic wrote: > >> > >> It must be a way to INSERT objects in the database > without looking up > >> for all the references, but I am not able to find > it. > >> > > > > My problem is similar as yours, with a single > difference. > > I don't mind loading all the references because I > need them in the > > program. But I don't know how to insert object and > disable an attempt of > > inserting in related tables. If I put cascade = > cascadeType.PERSIST, I get > > an exception (as you do). If I don't put cascade = > cascadeType.PERSIST > > (which is logical), I get an exception. Since I'm > new in JPA, I'm quite > > lost now. > > > > > > -- > View this message in context: > http://www.nabble.com/How-to-PERSIST-object-without-loading-references--tp16472647p17784459.html > Sent from the OpenJPA Users mailing list archive at > Nabble.com.