-->
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.  [ 3 posts ] 
Author Message
 Post subject: Selective Loading (partially populating an entity object)
PostPosted: Fri Aug 13, 2004 12:44 pm 
Newbie

Joined: Fri Aug 13, 2004 12:25 pm
Posts: 7
Location: Boston
Hibernate version: 216

This question applies more to the design than implementation - hence no code is provided.

A very simple scenario:

I have an entity object called User.java which has 6 fields (consider all of them Strings for now - except the id field) :

- id
- name
- email
- phone
- dob

Which maps to a MySQL table called USER, and each field in the object instance maps to a column in the USER table.

My mapping document is also simple:

<hibernate-mapping package="ka">
....<class name="User" table="USER" proxy="User">
........<id name="id">
............<generator class="native"/>
........</id>
........<property name="name" />
........<property name="email"/>
........<property name="phone" />
........<property name="dob"/>
....</class>
</hibernate-mapping>


I can easily load/save/update the object to-and-from the USER table without any problems (of course!).

However, let's say I only want id, name and email fields to be loaded from the database when I run session.load(...). Imagine, that I have a large entity object with 120 fields each mapping to a column in a db table (that has 120 columns). In the "list" view of the items, I only want to show, say, 8 of the 120 fields - but if Hibernate does not provide a way to some how "Mask" the rest of the 112 fields, then everytime I will have to fetch all the 120 fields from the database - even if I only want 8 of them.

If, let's say, I remove one of the property declarations from the mapping document - for instance <property name="name" />, then Hibernate only loads the id, email, phone and dob. The value of "name" field remains null. But does Hibernate provide a dynamic masking or dynamic selection support for a persistence object whose fields and property mappings have already been statically defined??

We are currently using a Selective Query work-around for obtaining this feature (outside of Hibernate) - we create dynamic SQL strings based on the type of view selected by the user.

Gurus, please help.

Thanks.
Kartik


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Just use a projection query like "select u.firsntame, u.lastname from User u"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 13, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
- projection queries
- lazy property fetching in Hibernate3
- iterate() and second level cache
- etc.

This is really a design concern, it won't make a performance difference in almost all cases. Optimize for row reads, not column reads.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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