ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Per Magne Bjornerud" <PMBjorne...@interlect.co.jp>
Subject Mapping data to subclasses
Date Thu, 12 Oct 2006 06:37:06 GMT

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