jQuery in Action, 2nd edition*
The moose likes Spring and the fly likes ParameterizedRowMapper That Maps Object List to Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "ParameterizedRowMapper That Maps Object List to Object" Watch "ParameterizedRowMapper That Maps Object List to Object" New topic
Author

ParameterizedRowMapper That Maps Object List to Object

darin ramdhanie
Greenhorn

Joined: Mar 21, 2013
Posts: 6
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

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

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.


[How To Ask Questions][Read before you PM me]
darin ramdhanie
Greenhorn

Joined: Mar 21, 2013
Posts: 6
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
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1646
    
    7

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
darin ramdhanie
Greenhorn

Joined: Mar 21, 2013
Posts: 6


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

Joined: Mar 07, 2010
Posts: 1646
    
    7

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.
 
wood burning stoves
 
subject: ParameterizedRowMapper That Maps Object List to Object
 
Similar Threads
Recursive code
ORM as compared to JDBC
retrieving object hierarchy - many-to-one?
Mapping Question
Creating Objects -> Generating Table using Collections