Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JDK 5 Generics support to HibernateTemplate's returned Lists [SPR-3128] #7814

Closed
spring-projects-issues opened this issue Feb 6, 2007 · 4 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Karl Moore commented

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

@spring-projects-issues
Copy link
Collaborator Author

Bruce Brouwer commented

I have recently added a forum post that is somewhat related to this topic: http://forum.springframework.org/showthread.php?t=66139

I would love to contribute my code, and maybe even help out with the HibernateTemplate thing, but I have no idea how to proceed.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We revised most template signatures for Spring 3.0 M2, including HibernateTemplate which is based on Java 5+ as far as possible now.

Juergen

@spring-projects-issues spring-projects-issues added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants