| Author |
Spring Jdbctemplate mapping a one to many example is this the most efficient or simple way
|
Tony Evans
Ranch Hand
Joined: Jun 29, 2002
Posts: 521
|
|
Is this the most efficient or simple way to code a ResultSetExtractor
the mapper
the DAO
Thanks for any reviews an helpgul hints, this is not about Jdbctemplate vs hibernate, I just want to look at the best way to utilise Jdbctemplate
|
 |
Bill Gorder
Bartender
Joined: Mar 07, 2010
Posts: 1282
|
|
You use one or the other. A RowMapper is the preferred way for mapping one result object per row, ResultSetExtractor is for one result object for the entire ResultSet. There is no performance difference but the RowMapper does more for you and you don't have to iterate yourself.
Also make sure you type these so you don't need the casts.
To answer your question a ResultSetExtractor would usually look something like follows: (I would definitely look at initializing your Fund list in your Portfolio object that way it will never be null when you create a new Porfolio and you can just get it and add to it)
For this case a row mapper can do what you need an you can do away with the result set extractor altogether:
If there is more than one row then will get a list back in both cases.
You would use it as follows:
|
[How To Ask Questions][Read before you PM me]
|
 |
Tony Evans
Ranch Hand
Joined: Jun 29, 2002
Posts: 521
|
|
Thanks Bill Gorder
Thats food for thought will code your way try it out, I like this I would definitely look at initializing your Fund list in your Portfolio object that way it will never be null when you create a new Porfolio it will remove that if block.
Thanks Tony
|
 |
 |
|
|
subject: Spring Jdbctemplate mapping a one to many example is this the most efficient or simple way
|
|
|