I’m in the process of creating a front end for a Database Driven application and Could do with some advice. I have the following basic entities in my database:
- aspect
- aspect_value
As you can image I can have many aspect value to each aspect so that when a user records an aspect they can select more than one value per aspect… simple.
I’ve created an POJO entity to model each aspect an my question is this… using Spring and the jdbcTemplate how would I be able to create the desired composite relationship using org.springframework.jdbc.core.RowMapper i.e. each aspect object containing one or more aspect value ojects? And for that matter I would appreciate if you could please let me know if this would be the best way to do it. I’m keen at some point to delve deeper into ORM but I’ve been put off so far by the number of issues I’ve encountered which has slowed down my development and led to the decision to use jdbcTemplate instead.
Thanks
You can use a
RowMapperif you are storing aspect_values in your aspect object as objects. Each call toRowMapperreturns an object so you’ll end up with a collection of aspect_values. If you need to build an aspect object (or objects) with values contained in the aspect_value table then aResultSetExtractoris the better choice.Here are my examples as promised. I have to type these in by hand because our development network is on an internal network only so any typos are copy errors and not errors in the code. These are abbreviated versions of inner classes in my DAO:
This maps a single row in the ResultSet to an object:
ResultSetExtractorworks on the same idea except you map the entire set yourself instead of just converting a row into an object. This is useful when your object has attributes from multiple rows.