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.  [ 2 posts ] 
Author Message
 Post subject: Best Practice: Returning select fields from association
PostPosted: Thu Mar 30, 2006 5:37 pm 
Newbie

Joined: Thu Jan 12, 2006 6:02 pm
Posts: 9
Hibernate version:
3.1
Mapping documents:
Using annotations
Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
MySQL 5.0.18
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A

I run across this often and don't know the best practice. I have an association (say many-to-one) between object1 and object2. object1 has-a object2. For our application, when we deal with object1, we are really only interested in a couple fields in object2 (e.g. first name and last name properties). object2 is a huge object and I'd rather not have to load all of it when loading object1. I just want the name fields of object2, but I'd like those fields to be loaded in the same select as the object1 load.

How do people handle this? I've looked at secondary tables and wasn't sure that was what I wanted. I thought I read somewhere that we could map a single table to mulitple entities (so we could have a "mini" object2), but again, not sure that's what I want or allowed with annotations (plus the duplication of the mapping properties in the mini). I also read that if one can't figure out how to do something, it can probably be handled by User types. Never used those.

Any help is appreciated.

Jim


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 5:55 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
If you need just few fields in the light object then duplication should not be a big deal and actually can be addressed at XML level by defining appropriate entities and reusing them.

If usually you need the light object then mapping could look like
<many-to-one name="zzzz" entity-name="light"/>

and then use some utility method to get full object when necessary.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.