开发者

Getting a list of objects in Hibernate returns a list of a single object

开发者 https://www.devze.com 2023-04-12 20:33 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号