-->
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.  [ 3 posts ] 
Author Message
 Post subject: Saving array of polymorphic objects
PostPosted: Wed Jul 22, 2009 12:03 am 
Newbie

Joined: Tue Jul 21, 2009 11:54 pm
Posts: 2
public class BaseObject
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual Container Container { get; set; }
}

public class Object1 : BaseObject
{
public virtual string Prop1 { get; set; }
}

public class Object2 : BaseObject
{
public virtual string Prop2 { get; set; }
}

public class Container
{
public Container() { Objects = new List<BaseObject>(); }
public virtual List<BaseObject> Objects { get; set; }
}

Container container = new Container();
container.Objects.Add(new Object1());
container.Objects.Add(new Object2());

Is that possible to save such object model with hibernate?
I tried all three: subclass, joined-subclass, union-subclass to save Object1 and Object2. Nothing works.

Can anybody point me where to read how to save List of polymorphic objects?

Thank You.


Last edited by RomanGuzi on Wed Jul 22, 2009 2:47 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Saving array of polymorphic objects
PostPosted: Wed Jul 22, 2009 2:06 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
All three strategies should work here, that's basic functionality. You must have done something wrong. Can you post one of your approaches (mapping + code where you save/update) ?

And that's possibly a typo ?

public Container() { Container = new List<BaseObject>(); }

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Saving array of polymorphic objects
PostPosted: Wed Jul 22, 2009 4:53 am 
Newbie

Joined: Tue Jul 21, 2009 11:54 pm
Posts: 2
I had three levels of inheritance and NHibernate fails to understand it. Simplified it and it is working now.
Thanks. You gave me a punch to find solution. Even though not perfect enough.
I'll try to find time to post here in order to make it the way I want.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.