-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How do you declare the <element> tag for value objects
PostPosted: Wed May 18, 2005 12:03 am 
Newbie

Joined: Tue May 17, 2005 4:52 pm
Posts: 1
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


Top
 Profile  
 
 Post subject: Re: How do you declare the <element> tag for value obj
PostPosted: Wed May 18, 2005 1:55 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
DWeinmann wrote:
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>

The mapping above means you have an ISet whose elements are strings. And you have an ISet whose elements are objects with a string property, so you have to use <composite-element> to map that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.