ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anderson Forteleza" <afortal...@gmail.com>
Subject Re: Mapping data to subclasses
Date Thu, 12 Oct 2006 12:15:03 GMT
Hello there Per Magne...

...check section 3.5.6 - Inheritance Mapping, of the DataMapper Developer
Guide [
i think there's an explanation there that covers your case :)

Anderson Fortaleza

On 10/12/06, Per Magne Bjornerud <PMBjornerud@interlect.co.jp> wrote:
> Hello,
> I have a database where several subclasses are mapped to the same table.
> I'll stick to the standard example here. Assume
> Base class: Person
> Subclass: Employee
> Subclass: Customer
> In my application, I mostly use instances of Employee or Customer
> objects. But in the DB, they are both stored to the Person table. In
> addition to the object properties, they have a PersonType id to know
> which is which.
> Is there any way to set up iBatis mapping so the objects I get returned
> will be instances of the different subclasses, depending on the
> PersonType field?
> I want to do a very simple "SELECT * FROM Person WHERE Id = X" and map
> it to an object.
> Obviously identical <select> elements for each subclass and an
> additional lookup to know the type of each object before I select them
> isn't really an option. Is there a way for iBatis to handle this?
> I guess the alternative might be to create instances of Person objects
> and add a GetCorrectInstance() method that will return objects of
> correct subclass. If iBatis cannot help me do what I want, I'd also be
> happy for some tips, patterns or keywords to help me find the best
> possible workaround.
> --
> Per Magne Bjornerud

View raw message