Problem removing association

Posts   
 
    
nero2001
User
Posts: 8
Joined: 10-Oct-2006
# Posted on: 07-Nov-2006 16:29:41   

Hi there,

i have 2 tables, Account and Client, with a relation one-to-many from Account to Client.

In table Client, i have a foreign key for the primary key of table Account.

When i associate a Client to an Account, i do the following: client.accountID = value;

When i want to remove that association, i do the following: client.accountID = null;

Here's the problem: Sometimes when i try to remove the association, it doesn't work! Does anyone know why sometimes it works, and sometimes it don't????

Thanks in advance. Nelson

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 07-Nov-2006 16:45:42   

Hello,

I think is better to use client.Account=currentAccountEntity (where currentAccountEntity is your account entity you fill before) Thanks to that, it's easier to save your entity for a new entity(only have to save client and account is saved). For removed, you can used client.Account=null;

For your case when it doesn't work, did you make a fetch or did you modify the account entity wich is related to the client entity before you saved the client? Or before you save account entity, is your client entity always in the account.Client entity collection?