• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ParameterizedRowMapper That Maps Object List to Object

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Any advice on this will be appreciated.

ParameterizedRowMapper

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
darin ramdhanie
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
darin ramdhanie
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bill Gorder wrote:Sure take a look at this.
http://books.google.com/books?id=k7KZkl4PyhYC&pg=PA292&lpg=PA292&dq=When+to+use+ResultSetExtractor&source=bl&ots=YnYiEg6b6g&sig=PHFgG9BCFfKgkaVNYYAc-VpSbH8&hl=en&sa=X&ei=JQ1NUa7iGa-l4AOWn4CwDA&ved=0CEgQ6AEwAzgK#v=onepage&q=When%20to%20use%20ResultSetExtractor&f=false



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>
<2, dad>
<3, aunty>
<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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic