-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Question about one-to-many relation
PostPosted: Fri Feb 02, 2007 7:44 am 
Newbie

Joined: Wed Jan 24, 2007 10:29 am
Posts: 5
I have some problem with the one-to-many relation.
I have a Class User and a Class UserLevel. The relation between User and UserLevel is 1-n.
So, I have following configurations:
In User.hbm.xml
Code:
<set name="userLevels" inverse="true">
            <key>
                <column name="user_id" />
            </key>
            <one-to-many class="yuguo.its.data.model.UserLevel" />
        </set>


In User.java

Code:
private Set userLevels = new HashSet(0);

Code:
public User findById( java.lang.Integer id) {
        log.debug("getting User instance with id: " + id);
        try {
            User instance = (User) getSession()
                    .get("yuguo.its.data.model.User", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }


I use User.findById to get an instance of User. Then I use user.getUserLevels to get the UserLevel set. In the database, I have two UserLevel assigned to the User. But the set return by user.getUserLevels is empty.
When I use UserLevelDAO.getByExample(User), the returned list is correct.
My Hibernate version is 3.1.
What's the problem?

Thanks in advance!


Hailong Zhang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.