As far as hibernate is concerned, there is no difference.
As far as java is concerned, the first option is faster because the string + string approach uses StringBuffer, which is synchronized. Also, java can't put the entire string in its string table.
As far as JDBC is concerned, the first approach is faster, because it creates a PreparedStatement instead of a simple Statement. PreparedStatements are precompiled and stored... somewhere. In driver memory, or in the server, I don't know. Have a look at the JDBC javadocs for more info.
As far as "clean" programming goes, I would recommend putting all queries into .hbm.xml files as named queries. That way. if you ever have to modify a query in use by in-production software, you only have to re-distribute mapping files instead of recompiling entire projects.
|