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: Inheritance problem
PostPosted: Fri Dec 15, 2006 11:06 am 
Newbie

Joined: Wed Sep 13, 2006 4:30 pm
Posts: 4
Hi Folks..

Here is my situation..

I have an Entity class that has a Notes property which is a collection of Note. Notes is of type IList (and I use ArrayList).

I have a Member class that inherite from Entity and I would like Member class to have a NotesMaraudage collection of Note.


The problem I'm facing is that in the Notes table in the DB, both Notes from Entity and NotesMaraudage collection will have IdEntity set

to the same Id. When loading a Member, how will this work out? I mean how will nhibernate know which note goes to Notes or NotesMaraudage ?


Right now, what I did is create a NoteMaraudage class that inherite from Note (with a discriminator) and used that class for the collection

of NotesMaraudage. That way, nhibernate can use the discriminator value to load notes properly. but NoteMaraudage class is completly emtpy!


Any comments about this would be greatly appreciated.


Also, in the member.aspx page, I display the related information and at the bottom, I list all notes with a modify link. When someone

clicks the link, he is offer to modify the note. Once modified, how can I save it to the DB ? should I use the Session.save(note) directly

or should I go through Member.Notes[index] and change properties there and then save Member ? The latter seems best to me.. but I just

don't know how to find the right index .. should I use something else than a IList for this?



Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 16, 2006 1:30 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
anyone on this?

I kinda have a very similar problem !

Cheers !


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 23, 2006 5:33 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
I'm not sure I fully understand your situation but here's what I gathered...

If your Entity class is abstract then I'd simply not put the Notes collection in the base class but rather in the Member class (as NoteMaraudage). But if it isn't abstract, the only solution I can offer is to consider composition decorating Entity with Member instead of inheritance and returning base.Notes in your NotesMaraudage getter. It sounds like all you want is a property name difference since you said the NotesMaraudage class is empty which indicates maybe a design change is in order. But maybe you can't change it.
Regarding your other question...
Whether you save the properties on Note directly or from within the Aggregate (Member) is up to you (I prefer doing all actions through an aggregate) since NHibernate is tracking whether the object is dirty or not. Just be sure you implemented .Equals and GetHashCode properly on Note and NHibernate should save updates on the properties just fine. Now if you are talking about adding/deleting Notes to Member collections then you should do that thru the Member class and not, say, Note.Member = member (assuming you have a bidirectional relationship).

_________________
If this helped...please remember to rate it!


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.