Hello,
I'm having trouble making any changes to my many-to-many collection. I get a "object already associated with session" message but nothing happens when I do Update() ... I also tried Save() and SaveOrUpdate() but it doensn't want to do it.
When I make changes to my joining table directly in the database I can see that the collections are correctly populated ... so reading works, I just can't get it to write. This is my code:
Mapping file:
Code:
...
<bag name="Keywords" table="KeywordsFiles" cascade="none" access="nosetter.camelcase" lazy="true" inverse="false">
<key column="FileID"/>
<many-to-many column="KeywordID" class="Bearch.DataEntities.Keyword, Bearch" />
</bag>
...
...
<bag name="Files" table="KeywordsFiles" cascade="none" access="nosetter.camelcase" lazy="true" inverse="true">
<key column="KeywordID" />
<many-to-many column="FileID" class="Bearch.DataEntities.File, Bearch" />
</bag>
...
File.cs
Code:
public IList Keywords
{
get { return keywords; }
set { keywords = value; }
}
Keyword.cs
Code:
public IList Files
{
get { return files; }
set { files= value; }
}
Client code
Code:
IList files = session.CreateCriteria(typeof(File)).List();
IList keywords = session.CreateCriteria(typeof(Keyword)).List();
//Just take the 1st file and 1st keyword and associate them
File f = (File)files[0];
Keyword k = (Keyword)keywords[0];
//I'm adding both sides to each other to make sure
f.Keywords.Add(k);
k.Files.Add(f);
//I update both but both give the same log message (see below)
session.Update(f);
session.Update(k);
Log
Code:
2005-06-16 18:58:14,308 [3588] DEBUG NHibernate.Impl.SessionImpl [] <> - object already associated with session
2005-06-16 18:58:14,308 [3588] DEBUG NHibernate.Impl.SessionImpl [] <> - object already associated with session
I'm out of ideas about what could be wrong.. I realize that calling the update on the class that has inverse=true will result in no update, but I'm calling both here (and one of them is inverse=false) so why is it not doing the update? I also tried doing lazy=false but that didn't help much either. I originally copied this code from one sample - it didn't have a setter method on the Keywords and Files properties but instead a new ArrayList() initialization of the private variable ... but having it like that was no better than the way I have it now.
What am I missing here?
Thank you,
Tomas