I'm reading the Advanced Mapping Concepts chapter in the Hibernate In Action book and I would like to implement the element tag in a set for a value object (page 212) in c#.
My sample classes are of Account and Note, in which Account has a collection of Notes. The idea that I had was that since notes will only have the life cycle of an Account, I wanted to treat it like a value object.
So my Account class looks like...
Code:
ISet theNoteList = new Iesi.Collections.HashedSet();
public ISet NoteList {
get { return theNoteList; }
set { theNoteList = value; }
}
public void AddNote(Note aNote) {
NoteList.Add(aNote);
}
And the Note class...
Code:
string theNoteText;
public string NoteText {
get { return theNoteText; }
set { theNoteText = value; }
}
So part of the mapping file for the Account is...
Code:
<set name="NoteList" lazy="true" table="Notes" >
<key column="AccountID" />
<element type="String" column="NoteText" />
</set>
Now, when I go to persist the account, I get this error...
Code:
could not synchronize database state with session
Exception: System.InvalidCastException
Message: Object must implement IConvertible.
The same persisting logic is used to successfully save the Account without the Note class, so I assume the error lies in the mapping and variable declaration in the Account class.
I have exhaustively examined the book sample and searched the net, but I can not find the light.
Anyone have any ideas?
Regards,
Dan