-->
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: One-to-many problem under same transaction/session
PostPosted: Fri Jun 08, 2007 5:38 am 
Newbie

Joined: Fri Jun 08, 2007 5:21 am
Posts: 2
I have mapped classes User and Division

Division has this mapping

<bag name="Users" inverse="true">
<key column="Division" />
<one-to-many class="User"/>
</bag>

And user has this

<many-to-one name="Division"/>

Then if i do following under same transaction/session even if i commit transaction it doesn't work.

Division division = new Division();
division.Name = "First";
session.Save(division);

User user = new User("nobody");
user.Division = division;
session.Save(user);


IList<Division> divisions = session.CreateCriteria(typeof(Division)).List<Division>();
foreach (Division div in divisions)
{
Console.WriteLine("Division - Name: " + div.Name);
foreach (User user in div.Users)
{
Console.WriteLine("Division User - Id: " + user.Id + " User: " + user.DisplayName);
}
}


No users are found....wierd....

But if i do this under that previous foreach users are returned.

IList<User> users = session.CreateCriteria(typeof(User))
.Add(Expression.Eq("Division", div))
.List<User>();

Until i close my current session i don't get any users from division. After closing session and opening new one and new transaction it works just fine. Is it a bug or am i doing something wrong?


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.