Hi,
In my project we're in the process of structuring database access logic. We've decided to try and incorporate SQL (as opposed to HQL) as our primary query language (using createSQLQuery), and thus would like to be as consistent with this as possible. The main arguments for doing this is:
* consistent, uniform code
* reuse of existing SQL
* readability for non-Hibernate literates
By using createSQLQuery it is required to fetch *all* properties for the related persister classes. I.e:
Code:
String sql =
"SELECT {PERSON.*}" +
" FROM PERSON P" +
" WHERE P.SSID = :ssId"
String aliases[] = new String[] {"P"};
Class classes[] = new Class[] {Person.class};
List qRes = session.createSQLQuery(sql, aliases, classes)
.setString("ssId", ssId)
.list();
In the cases where I'm only intersted in a single field from the result, fetching all columns intuitively seems to be inefficient. I might very well be wrong on this, though. My big concern is that the overhead related to this is heavy, which suggests using a mix of SQL and HQL. Any views on this would be greatly appreciated.
Regards,
Rubel