Announcement Announcement Module
Collapse
No announcement yet.
Class Hierarchies with RowMapper Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Class Hierarchies with RowMapper

    I wanted to know what the community considers the "best practices" in respect to mapping class hierarchies with Spring JDBC.

    We do not have the ability to use a full fledged ORM tool, however we are using the Spring JDBC to alleviate some of the tedious nature of JDBC. One class which we leverage very regularly are the BeanPropertyRowMapper for it's ease of use and the ability to have type insensitive bean property access from our result set.

    I have a class hierarchy that all maps back to a single table (taking the table-per-hiearchy approach for this small class hierarchy). As such, the table contains an classId column which can be used to determine what type of class should actually be instantiated. Ex. 1 = Manager, 2 = Employee, 3 = Contractor. All of these are "People" but each subclass of person has a few attributes which are unique to their class.

    My initial thought is to create a subclass of BeanPropertyRowMapper and try and inject this logic to say "if column A = 1 then instantiate a Manager and then do your nomral binding".

    Does this seem like a reasonable approach? Are there any other suggestions people may have that have worked for you?

    Thanks in advance for your replies,
    Justin N.
Working...
X