-->
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: question about fetching
PostPosted: Wed Jun 13, 2007 12:06 am 
Newbie

Joined: Fri May 18, 2007 12:29 pm
Posts: 7
I have a legacy database table which we're trying to map to Hibernate. The table has about 50 columns, many records and the data will be displayed in a grid. Only a small subset of the columns will be displayed in the grid and the columns in that subset is configurable by the customer.

Is it possible to configure at runtime which fields were being fetched by Hibernate? I'd like Hibernate only to fetch the fields which the customer has specified they'd like to view.

Thanks for any and all help!
bg4


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 12:56 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
You can use Hibernate Criteria queries with ResultTransformers.

Here's an example.

Criteria criteria = session.createCriteria(Car.class) ;
criteria.setProjection( Projections.projectionList() .add(Property.forName("name").as("name"))
.add(Property.forName("make").as("make"))
).setResultTransformer(new AliasToBeanResultTransformer(Car.class));
criteria.list() ;


Assume, Car has many more fields like top_speed, max_power etc. and user wants only name and make.

It is dynamic. Populate the projection list as per user preferences at run time.

The same can be realized using,
i) HQL Report queries.
ii) Native SQL queries.

ResultTransformer is not mandatory. You can omit it if are okay with handling object arrays.

----------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 11:06 am 
Newbie

Joined: Fri May 18, 2007 12:29 pm
Posts: 7
Thank you! Very helpful


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.