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.  [ 4 posts ] 
Author Message
 Post subject: Shortcut to setting many-to-one
PostPosted: Wed Dec 29, 2004 10:55 pm 
Beginner
Beginner

Joined: Sun Nov 07, 2004 4:19 pm
Posts: 38
I have a many-to-one mapping from class History to User

public class History
private User user;


Mapping
<many-to-one name="user" outer-join="true" column="USERTBL_OID"/>


In my updated routine I do (this works):

History history = historyDAO.get(11);
User user = new User(100); // OID passed in from the weblayer
history.setUser(user);

I didn't want to do the following:
History history = historyDAO.get(11);
User user = userDAO.get(100) // OID passed in from the weblayer
history.setUser(user);

since it would be an extra hit to the database to retrieve the user.

Is this okay?

Dino


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 5:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
yes
You can also set User to lazy=true and do session.load(User.class, id); it willnot hit the db

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 12:19 pm 
Beginner
Beginner

Joined: Sun Nov 07, 2004 4:19 pm
Posts: 38
Very nice. Is this documented somewhere? I think this is an extremely useful piece of info.

Dino


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can guess it from the javadoc :)
It is probably more explicit in Hibernate in Action too.

_________________
Emmanuel


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

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.