You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As pointed out in that forum thread, Spring's HibernateTemplate itself cannot support parameterized Lists simply because it needs to remain compatible with JDK 1.3/1.4. Note that Hibernate's Session API itself doesn't support generics either, for the same reason.
HQL-based queries aren't a good fit for generics in the first place: You only specify the result element type as part of the query String there, not as method argument. For that reason, not even the Java Persistence API (which builds on JDK 1.5+) supports generics for List results: see the "javax.persistence.Query" interface and its "getResultList()" method.
Hence, I would argue that there is simply no sensible way to provide this for HibernateTemplate, not even for a special generified version of it. At best, we could provide this for the "loadAll(entityClass)" method only, which would hardly justify the effort of maintaining a JDK 1.5+ version of HibernateTemplate.
I do see your point. Varargs would might make it more worth while, but again it's not a huge change.
Another thread that talked about a generic Dao suggested this style, but I'm not sure I'm convinced. @SuppressWarnings("unchecked")
public <T> List<T> findByNamedQueryAndNamedParam(Class<T> entityClass, String queryName, String[] paramNames, Object[] values) throws DataAccessException {
List<T> results = (List<T>) getHibernateTemplate().findByNamedQueryAndNamedParam(queryName, paramNames, values);
return results;
}
List<User> usersByName = persistenceManager.findByNamedQueryAndNamedParam(User.class, "user.byName", new String[]{"name"}, new String[]{"your value here"}); http://forum.springframework.org/showthread.php?t=25160
Corba the Geek opened SPR-3128 and commented
In Spring 2.0.x's HibernateTemplate, all the find() methods return unparameterized Lists.
Why not have 'find...()' and 'loadAll()' methods return a parameterizable List<T> like the SimpleJdbcTemplate?
This was discussed in:
http://forum.springframework.org/showthread.php?t=34526.
Affects: 2.0.2
1 votes, 8 watchers
The text was updated successfully, but these errors were encountered: