I am using Hibernate in my Spring Java EE application. I get the list of Users, where User is a bean specified in the applicationContext.xml as follows:
<property name="annotatedClasses">
<list>
<value>foo.bar.User</value>
</list>
</property>
The code that returns the list of users is the following; the returned list has the correct size, however all the objects seem to be the same object (I'm printing out the objects in my JSF file using ui:repeat.
public List<User> getAllUsers() {
Query q = currentSession().createQuery("from User");
List<User> allUsers = (List<User>) q.list();
return allUsers;
}
I suspect that the User is returned a single time, however cannot resolve the issue.
How can I make a Hibernate query to return all obj开发者_C百科ects?
The problem was that I had changed the primary key value, which was user_id to id. This caused the id column to be set to all zeros, hence it was always returning the 0'th object.
精彩评论