This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am trying to set the Parent List in a ParameterizedRowMapper how is this written or approached. I have two Objects one for parent and one for children however children contains a List. The parents for each child are stored in a separate table in the database and the mapping is 1 - many.
The select for the records for the parents will be done in a separate ResultSet. Will the mapping have to be done separately (separate ParameterizedRowMapper), if so how will i have to write the ParameterizedRowMapper this is the major concern how ParameterizedRowMapper is written to accommodate a list items.
Better for a scenario like this to create one join query and use a ResultSetExtractor. You will need to write the logic to aggregate the multiple parent rows for the child. Also FYI as of Spring 3.0, ParamaterizedRowMapper is equivalent to using the RowMapper interface directly.
Bill Gorder wrote:Better for a scenario like this to create one join query and use a ResultSetExtractor. You will need to write the logic to aggregate the multiple parent rows for the child. Also FYI as of Spring 3.0, ParamaterizedRowMapper is equivalent to using the RowMapper interface directly.
Do you have an example of this that you can share with me i want to see how its being done
I am just curious about the results i see that this will return a list of objects for me so lets say i have a children record that has :
firstName - john lastName - doe, dob - 1998-01-01, parent <1, mom>
<4, uncle>,phoneNo - 12345678
will the data be returned like that or will the data for firstName,lastName,dob and so on duplicate itself for each record in the list? I am asking this since i will not be returning firstName, lastName... into list elements in the view.
Just some clarification so i will have a clear picture when approaching this.
It depends on your join query and table structures. If you show us that we could better answer your question. The point is the result set extractor unlike the row mapper gives you full control over the result set so that you can iterate over multiple rows and collect the data to build an object with collections etc. The row mapper is more appropriate when mapping one result object per row.