aspose file tools
The moose likes Spring and the fly likes Spring Jdbctemplate mapping a one to many example is this the most efficient or simple way Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Reply Bookmark "Spring Jdbctemplate mapping a one to many example is this the most efficient or simple way" Watch "Spring Jdbctemplate mapping a one to many example is this the most efficient or simple way" New topic
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel/download
 
subject: Spring Jdbctemplate mapping a one to many example is this the most efficient or simple way
 
Similar Threads
HSQLDB - user lacks privilege or object not found
Spring-RowMapper-DB2-Stored Procedure
JDBC from Spring framework
RowMapper callback interface's mapRow can pull only one row?
Spring 101: DB Table to return a Map of Code,Description.