-->
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.  [ 13 posts ] 
Author Message
 Post subject: Entity with lots of columns...
PostPosted: Tue Jun 19, 2007 1:35 pm 
Newbie

Joined: Wed Jun 06, 2007 11:58 am
Posts: 13
I have this class Award mapping the Award table that has a lots of columns(30). When I do list awards I don't need more than few things (id, description) if I use a projection sql-query like below that will do it.

If I use hql that is way too slow because the extra work performed to fetch 30 columns per award.

Is lazy="true" on the field working ? Is there any other (better) way of doing ?


Code:
  <sql-query name="award.listing">
    <return alias="entry" class="Award"/>
    <![CDATA[
        SELECT
             cpa.award_id as {entry.id},
             cpa.description as {entry.description}
        FROM
             award cpa
       ]]>
  </sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 6:49 pm 
Regular
Regular

Joined: Wed May 05, 2004 8:01 am
Posts: 53
You could create a separate entity - AwardInfo (with less columns) and map it to the same database table.

Please rate if that helped.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 7:12 pm 
Newbie

Joined: Wed Jun 06, 2007 11:58 am
Posts: 13
I'm a bit afraid of second level cache that's going to cache two entities for same row leading to higher memory consumption.


I have to give it a try. The prev. approach would only have the drawback that I'd have to change some of the queries the rest would stay similar.

Thanks for the reply!!!
Q-2


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 1:44 am 
Beginner
Beginner

Joined: Fri Aug 12, 2005 7:05 am
Posts: 25
Location: TamilNadu
Hi Q-2,
You can use projection HQL query like below.

HQL : select property1,property2 from Award where ....

don't forget to rate....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 8:20 am 
Regular
Regular

Joined: Wed May 05, 2004 8:01 am
Posts: 53
Q-2 wrote:
I'm a bit afraid of second level cache that's going to cache two entities for same row leading to higher memory consumption.


I have to give it a try. The prev. approach would only have the drawback that I'd have to change some of the queries the rest would stay similar.

Thanks for the reply!!!
Q-2


so disable 2nd level cache for this particular entity.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 11:31 am 
Newbie

Joined: Wed Jun 06, 2007 11:58 am
Posts: 13
True but that is returning an array list of scalars... and no objects!

somu_ngm wrote:
Hi Q-2,
You can use projection HQL query like below.

HQL : select property1,property2 from Award where ....

don't forget to rate....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 11:36 am 
Newbie

Joined: Wed Jun 06, 2007 11:58 am
Posts: 13
Another way I found is to do create a Value Object (POJO) that extends Award

AwardSlim extends Award

and then do a HQL

select new AwardSlim( award.id, award.description )
from
where

that will return AwardSlims that are in fact Awards and is quite fast.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 12:01 pm 
Newbie

Joined: Wed Jun 06, 2007 11:58 am
Posts: 13
Another way would be to detach the little used column into AwardCharacteristics or a AwardDetail table that will be lazy=true but unfortunately that's going to be imply quite a bit of changes...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 4:38 pm 
Newbie

Joined: Wed Jun 20, 2007 9:29 am
Posts: 2
Hibernate should support column level lazy property. As far as I know it was in 3.0 road map
So all you have to do is to specify lazy="true" for the property.
Normally by default lazy="false" for properties, but can be enabled.
According to some documents
<cite>
Hibernate3 supports the lazy fetching of individual properties. This optimization technique is also known as fetch groups. Please note that this is mostly a marketing feature, as in practice, optimizing row reads is much more important than optimization of column reads. However, only loading some properties of a class might be useful in extreme cases, when legacy tables have hundreds of columns and the data model can not be improved

</cite>
I believe this is right for you case..
Hope this helps

EDIT: But of course.. it is never easy.. you should do bytecode instrumentation for this class.. CGLIB will not be enough *sad*


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 20, 2007 6:29 pm 
Newbie

Joined: Wed Jun 06, 2007 11:58 am
Posts: 13
I did read that info before and is not working, at least not in the way I expected. I need to see an example.

Thanks for writing back!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 1:12 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

You can use criteria with transformer (AliasToBeanResultTransformer)


select onlu fields what you want


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 5:04 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
I would use a database view which contains only the relevant fields. I think this would be the fasted solution because you delegate the work to the database.

In conjunction with Hibernate Tools the database views are generated just like tables and you have no additional work with mapping a result array to an object or transforming a result to an object.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 5:31 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
maitscha wrote:
I would use a database view which contains only the relevant fields. I think this would be the fasted solution because you delegate the work to the database.

In conjunction with Hibernate Tools the database views are generated just like tables and you have no additional work with mapping a result array to an object or transforming a result to an object.


Is this what you want?

If yes don't use views. you can mapped only selected columns in table. unnessary to create seperate view for selected columns


Amila

(Don't forget to rate if helps)


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