-->
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.  [ 6 posts ] 
Author Message
 Post subject: May I retrieve partial columns (properties) only?
PostPosted: Thu May 04, 2006 12:47 am 
Newbie

Joined: Thu May 04, 2006 12:31 am
Posts: 3
Hi,
I have one mapping file for a large table, which has more than 100 columns. Is there any way to just retrieve several columns and set other properties null? I hope I can get the collection of objects instead of just a resultset.
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 2:04 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If you use different classes for each "bit" of the table, then yes. You can't partially load objects, but you can break up tables into multiple classes. Hibernate will handle them correctly.

I do this from time to time. My approach is to put the "important" fields into the main class, then use one-to-ones to other classes that are mapped to the same table for the rarely-loaded/saved columns. To get the other columns, I just have to call myMainClass().getIncidentalObject(), or whatever.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 12:10 pm 
Newbie

Joined: Thu May 04, 2006 12:31 am
Posts: 3
Thanks! It's very helpful.
But what if the columns are all important and my usage model is that I may pick part of them to show in one page and another ones to show in another page. Does it mean I have to create many mapping files with classes for each page? Is it worthy to do that? I can forsee there might be some (class + mapping files) management issues after production.
BTW, in my usage model, the classes which map to the same table may be used as data fetching only. It's like database view. I may not do any insert/update/delete. Is there any option in mapping file that I can set to prevent users to do that? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 12:27 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
hsini_huang wrote:
BTW, in my usage model, the classes which map to the same table may be used as data fetching only. It's like database view. I may not do any insert/update/delete. Is there any option in mapping file that I can set to prevent users to do that? Thanks!


This link http://www.hibernate.org/hib_docs/v3/re ... n-property will help you regarding read-only derived properties by specifying insert="false" and update="false". Dont know if you were looking for something like that.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 7:08 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Also, <class mutable="false"> essentally puts insert="false" update="false" on every property, and additionally allows for some minor performance updates when creating entity persisters and derived SQL.

You can put multiple mappings in each file. So you can use one file to set up different classes for different parts of the table. If the "important" class includes lazy associations to the other classes, then you don't have to worry about anything after you've written the mapping file.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 3:04 pm 
Newbie

Joined: Thu May 04, 2006 12:31 am
Posts: 3
Thanks! Now I know how to design.


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