Subclass creation/removal with persisted parent class?

1 view
Skip to first unread message

deuce

unread,
Feb 20, 2009, 1:59:49 PM2/20/09
to nhusers
I have the following simple class structure, simplified for post:

class Person
{
public int ID;
}

class Student : Person
{
public Student(Person person){}
}

The problem I am facing is when I pass in the person and assign all
the values to this object including the ID, it wants to update when I
call SaveOrUpdate. I need to save the student WITHOUT modifying the
ID of the person. So since the person class has already been
persisted, I just need the INSERT for the subclass.

On the other end of this, how would I go about removing the Student
subclass BUT leaving the person?

Germán Schuager

unread,
Feb 20, 2009, 3:01:25 PM2/20/09
to nhu...@googlegroups.com

Sly

unread,
Mar 4, 2009, 9:47:04 AM3/4/09
to nhusers
I'm having the same problem. Is there any solution where I don't need
to redesign application?

On Feb 20, 10:01 pm, Germán Schuager <gschua...@gmail.com> wrote:
> Use composition instead of inheritance.
>
> http://www.cs.sjsu.edu/faculty/pearce/modules/patterns/analysis/Actor...

Dave

unread,
Mar 23, 2009, 9:48:42 PM3/23/09
to nhusers
Sly,

I ended up created a Role class with a subclass of Student. The
Role class points back to the Person class for traversing to that
object but is working fantastic and can be modified without affecting
the Person. When I want a Student, I ask for the Student via my
StudentRepository class and then can traverse to the Person class is
necessary.

-Good luck!
-Dave
> > > subclass BUT leaving the person?- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages