Jan 29th, 2012, 04:35 AM
JdbcTemplate and collections
Let's take as example the following SQL schema:
-LINE_ITEM: LINE_ITEM_ID (INT, PK), LINE_DESC (VARCHAR(45))
-ORDER: ORDER_ID (INT, PK), ORDER_DESC (VARCHAR(45))
-ORDER_LINE_ITEM: LINE_ITEM_ID (INT, PK), ORDER_ID (INT)
I'm trying to get an order from its ID using JdbcTemplate. Following the documentation, I need to use the queryForObject() method. I pass the SQL, the ID as an array of Object and the RowMapper implementation. But, in my case, the Order class has a List<LineItem> property, so it seems that I can't use queryForObject method directly. First, I need to query for the list of LineItem corresponding to the Order ID, so the List<LineItem> object is created. Then, I need to create the Order object, so I need to execute another query (also using the queryForObject method). At the end, I set the List<LineItem> property of the created Order object.
To conclude, I need to execute two SQL statements. Is that the only solution or I'm missing something? I've checked in the chapter 13 of the documentation, but didn't find.
Thanks for your help.
Last edited by Miko95; Jan 29th, 2012 at 04:38 AM.