-->
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: Large - wide tables
PostPosted: Tue Apr 01, 2008 4:14 pm 
Newbie

Joined: Tue Apr 01, 2008 3:52 pm
Posts: 5
I have several tables in my database that contain lots of columns.

For example, I have a table that contains 50 columns and let's say 1000 records. If I have a need to query this table for all of its records but require just two of the columns, is Hibernate the best approach to getting this data? This is assuming that I also have a need to get all 50 columns in some instances.

Basically I see a class with 50 members, and getting and setter methods for all of these members.

How would I configure Hibernate to just request the two columns that I want in one situation, but all 50 in another?

Thanks for the help in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 5:30 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
You'd map all 50 columns normally. So a regular query would be something like:

Code:
from Foo foo where foo.id = :fooId


If you want just a subset of the columns (especially a small one), you can use this method (discussed in chapter 14 of the manual):

Code:
select new Foo(foo.name, foo.description) from Foo foo where foo.id = :fooId


You'd need to provide a constructor for Foo with those two parameters in that order. Now, this assumes that calling programs know that they are getting half-baked Foo instances. I'm not totally cool with this so I tend to create another class for this purpose, but you can do what fits in your application. Note that nothing else will be populated on these Foo intances and associations won't lazy load, etc. They're ONLY what you select. Document what you're doing if you expose these guys to calling programs.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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.