-->
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.  [ 1 post ] 
Author Message
 Post subject: Dynamic Fields Possible?
PostPosted: Thu May 06, 2010 6:46 pm 
Newbie

Joined: Thu May 06, 2010 6:36 pm
Posts: 1
class Question {
long id; // primary key
String description;
}

class Vote {
long id;
long question_id; // points to question's id
boolean vote; // 0 = no, 1 = yes;
}

I have one class per table mapping set up and I am not using hibernate to generate my java classes

My issue is that I want to display the data in the following form:

Description | Total Yes | Total No
Do you like Red? | 10 | 2
Do you like blue? | 20 | 1

So my original query looked like:

from Question;

This would select all questions. Now I want to add the count(*) to the query result.
I do not want hibernate to return just a generic multi dimensional List of objects. I would like to find a way to "tack on" the count(*) as a dynamic field in the java object
so I could use reflection to say getTotalYes() votes. The reason I do not just add a member variable is that the count values are only used for visual display in one part of the app.

Is there a built in way to do this or do I have to either return a generic results set/add a member variable.

I don't like adding the member variable because then I am pushing interface elements down to my data layer and I don't like the generic Lists since I would have to go back and change a lot of code.

Any ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.