Announcement Announcement Module
Collapse
No announcement yet.
JdbcTemplate and collections Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdbcTemplate and collections

    Hi,

    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, 05:38 AM.

  • #2
    Seems like a homework assignment (judging from the tables).. I suggest take a look at the API and classes provided. What you want is to execute a single query (not 1+N queries, I suggest google for that). You want to use a ResultSetExtractor and not a RowMapper.

    Comment

    Working...
    X