-->
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: Manipulating result list returned to the presentation layer?
PostPosted: Fri Aug 06, 2004 9:12 am 
Beginner
Beginner

Joined: Fri Aug 06, 2004 9:01 am
Posts: 21
Hey all, first time poster. I've been working with Hibernate for a short while now, and am at a point where I am trying to manipulate the query result list returned back to the presentation layer (JSPs).

I am using the Criteria class and below is a simple example of what I want to accomplish.

Quasi SQL:

SELECT A, B
FROM SOMETABLE
WHERE A="SOMEVALUE1" AND C="SOMEVALUE2" AND D="SOMEVALUE3"


I can create a Criteria and load a class that has A,B,C,D setter/getters but the list returned always contains A,B,C,D where I want it to just return A and B.

Can't seem to figure out how to accomplish a limited/constrained/subset result list with Criteria.

Seems like using the ResultTransformer API may be the way to do it, but I can't find anything BUT the API doc on it and its not very clear what the ResultTransformer interface is used for.

Any examples anywhere?
Any recommendations on how to accomplish this relatively simple SQL task using Criteria? Or is it better to use an alternative querying component within Hibernate? (i.e. HSQL)


Thanks ahead of time for any responses. If you need an additional info, please let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 9:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Using HQL for that is defiinately better, if you don't need the dynamic features of criteria.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 06, 2004 10:13 am 
Beginner
Beginner

Joined: Fri Aug 06, 2004 9:01 am
Posts: 21
OK, but is it possible to control the result list attributes/elements returned from a query using Criteria?

It seems like you can only specify the "FROM" and onward of a respective SQL query with Criteria...but not the SELECT aspect.

Right now, since my response presentation in JSPs are dependent on what fields the user wants to view, I am traversing through the relative Class object's fields and displaying only those that are considered "checked for viewing". The overhead is not tremendous, since the classes are small, but I'm sure there is a cleaner way to do it! ;)

I like the idea behind the Criteria, and may indeed need to utilize the dynamic features in the future...the only pitfall I'm finding is the lack of "SELECT" ability to limit the returned elements, but that may be against the design principle of OR mapping to the Class via Criteria.

I don't want to get too detailed, nor bore you with my application issues...but essentially what I am doing now is as follows (read if you'd like):

- Maintaining a HashMap of user desired view fields based on what is selected in the form.
- Maintaining a HashMap of user defined select fields and values based on what is selected in the form.
- Maintaining a HashMap of user desired matching (Partial or Exact) or the above selected fields.

Based on the 2nd and 3rd collections, I define the Criteria.
The 1st collection determines what is displayed at the presentation layer.

I'm trying to determine how best to encapsulate the desired data, which differs (potentially) from the actual selection criteria fields.

As mentioned above, I traverse through the 1st HashMap of desired view fields for each row of the returns Object Mapping result list based on the Criteria driven query (so it is two JSTL embedded forEach loops...which results in duplication, overhead, and essentially undesireable code from my perspective, although it works great and is still fast (classes are relatively small).

So that's the skinny, sorry for the novel...but any recommendations you can provide would be greatly appreciated!

Thanks again


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.