db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: Saving two related objects
Date Fri, 17 Feb 2006 14:41:58 GMT
If you have a forgeign key field, there should be a method
like setTable2Key(ObjectKey) in it.  You should use this to
set the relationship.  E.g.:

second.setFirstKey( first.getPrimaryKey() )

I'm not sure where you're finding a Torque method with 
the signature setFirstClass( First value )?


> -----Original Message-----
> From: Matteo Barbieri [mailto:m.barbieri@ste-energy.com] 
> Sent: Friday, February 17, 2006 9:29 AM
> To: Apache Torque Users List
> Subject: Re: Saving two related objects
> 
> 
> After some more tests I found that when I save the second 
> object, Torque tries to save it with 0 as foreign key, even 
> if second.FkFirstClass() gives me the correct id of first.
> 
> So what do I do?
> 
> Bye
> 
> Matteo Barbieri ha scritto:
> 
> >Hi,
> >maybe it's a stupid question, but I got an error that I 
> don't know why 
> >it happens.
> >
> >I have two tables that are related by foreign key.
> >
> >I have to create one istance of both objects and to save them.
> >
> >I do something like this:
> >
> >FirstClass first = new FirstClass();
> >SecondClass second = new SecondClass();
> >
> >first.save();
> >
> >second.setFirstClass(first);
> >second.save();
> >
> >the first object is saved correctly, but then I got an SQLException:
> >
> >java.sql.SQLException: Cannot add or update a child row: a 
> foreign key 
> >constraint fails
> >
> >I've tried to print both objects before every saving and the second 
> >object has the correct foreign key.
> >
> >Any idea?
> >
> >Thanks
> >
> >  
> >
> 
> 
> -- 
> Matteo Barbieri
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication
or may otherwise be privileged or confidential and are intended solely for the individual
or entity to whom they are addressed.  If you are not the intended recipient you may not rely
on the contents of this email or any attachments, and we ask that you  please not read, copy
or retransmit this communication, but reply to the sender and destroy the email, its contents,
and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying
of this communication is strictly prohibited.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message