-->
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: Objects inside Objects...
PostPosted: Tue Mar 07, 2006 5:11 am 
Newbie

Joined: Tue Mar 07, 2006 4:56 am
Posts: 17
Hello together,

I'm also a newbie to nHibernate (and c# as well, but that's a different story). I like to build a stronger type check into my object. I know I can't simply use a custom IList object, since these objects get replaced with the nHibernate version of the collection object.

So my plan is, to build a wrapper around a normal IList and serialize this collection. How do I manage to serialize this object together with it's parent? Here is a little code snippet:


public class User
{

private IAddress m_Address;

public User( )
{
m_Address = new AddressObj();
}

public IAddress Address
{
get
{
return m_Address;
}
}
}


public class AddressObj
{
private IList m_List;

public IAddressEntry this[ int index ]
{
get
{
return( (IAddressEntry) m_List[index] );
}
set
{
m_List[index] = value;
}
}

public int Add( IAddressEntry value )
{
return( m_List.Add( value ) );
}

public int IndexOf( IAddressEntry value )
{
return( m_List.IndexOf( value ) );
}

public void Insert( int index, IAddressEntry value )
{
m_List.Insert( index, value );
}

public void Remove( IAddressEntry value )
{
m_List.Remove( value );
}

public bool Contains( IAddressEntry value )
{
return( m_List.Contains( value ) );
}

}


Ok, how do I define my XML so it would serialize my IAddressEntry objects from the m_List member? Is this possible?

Regards, M. Heine...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 2:21 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I have done this by embedding the collection in a component, like so:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" >
   <class name="User" table="..." >
      ...

      <component name="Address" class="AddressObj" access="nosetter..." >
         <list name="m_List" access="field..." >
            <key column="UserID" />
            <index column="idx" />
            <one-to-many class="IAddressEntry" />
         </list>
      </component>
   </class>
   
   <class name="IAddressEntry" >
      ...
   </class>
</hibernate-mapping>


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.