I would like to know what is the best practice to write the sql code with Spring. I don't want to write "select this from that" in my java classes. I was thinking of :
1. Using a property file (sql.properties) to write all the necessary sql code -> sql.sqlCountTrades=select count(*) from mytradetable 2. Use a PropertyPlaceholderConfigurer to read the property file 3. Set the sql properties of a dao bean, using values from the property file -> <property name="sqlCountTrades"><value>${sql.sqlCountTrades}</value></property>
This works, but it is very painful to write. Is there a good method to write all the sql out of the java code ?
This sounds like iBatis Map files, but is there a way to do it without iBatis ?
If externalizing sql is a big concern for you I would definitely recommend going with IBatis as you persistence solution. However, it would be very easy to just wire another attribute of your DAOs with the actual sql being fed from your spring config file.