You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Jim Menard <ji...@io.com> on 2003/12/18 17:47:05 UTC

IDs not generated until after save?

I'm trying to confirm my understanding of primary/foreign key 
associations in newly-created objects. With the code

	BillAccount account = new BillAccount();
	Address address = new Address();
	account.setAddress(address);

	address.save();
	account.save();

I see the exception
	ExecInsert: Fail to add null value in not null attribute 
billing_address_id

Is it true that the address's primary key is not set until after the 
save? (I've used another Object/Relational package where the id is set 
in memory before the save.)

If the primary key is not set until after the save, then it looks like 
I can't associate the address with the account until after the address 
has been saved. I have to write my code like this instead:

	Address address = new Address();
	address.save();

	BillAccount account = new BillAccount();
	account.setAddress(address);
	account.save();

Thank you for your help.

Jim
-- 
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"Any sufficiently advanced technology is indistinguishable from a
rigged demo." -- Unknown


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