-->
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.  [ 5 posts ] 
Author Message
 Post subject: Data as column titles
PostPosted: Thu Feb 14, 2013 10:17 am 
Newbie

Joined: Thu Feb 14, 2013 10:04 am
Posts: 4
Hi everyone. I am new to HIBERNATE and am having trouble with a query I am trying to put together. I hope someone in this forum can help ;)


I have several tables related to one another.
In one table I have a property "CarType" which is later linked to other tables.
Users will manage "CarType" themselves


My challenge is as follows:
i need to set a query that enumerates all "CarType" and sets each CarType entry as one column (so I can populate those columns with data from other related tables)
Anyone has any idea on hoy I could do that.
TKS in advance for your help


Top
 Profile  
 
 Post subject: Re: Data as column titles
PostPosted: Fri Feb 15, 2013 3:38 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
Sorry, I didnt get this :
i need to set a query that enumerates all "CarType" and sets each CarType entry as one column (so I can populate those columns with data from other related tables)

you need to have list of cartype and then save it somewhere columns wise
like each entry in cartype will be a new column.

Please elaborate some more

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


Top
 Profile  
 
 Post subject: Re: Data as column titles
PostPosted: Fri Feb 15, 2013 8:17 am 
Newbie

Joined: Thu Feb 14, 2013 10:04 am
Posts: 4
Lets say we have the following tables:
1.Cars
2.CarTypes
3.Salesmen
4.Sales

Table relations:
"Cars" is related to "CarTypes"
"Sales" is related to "Salesmen", "Car", "Cartype" and has a field called "SalesPrice"

I need to produce a table where columns are: Salesmen, Cartype1, CarType2, CarType3...(as many columns as CarTypes we might have)
In each row we would find the name of the salesman, total value of sales for each "CarType" he sold.

Since CarTypes might change over time, I need columns to build dynamically so I do not need to build a new query every time CarTypes change.


Top
 Profile  
 
 Post subject: Re: Data as column titles
PostPosted: Fri Feb 15, 2013 9:04 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
okay. I got it .

First let me tell you how to get data rowwise as in :

SalesMan , Cartype1
SalesMan , Cartype2
SalesMan , Cartype3
SalesMan , Cartype4
...............

select s.salesMan, sct.carType from SalesMan s
join s.car sc
join s.cartype sct

Now to get the data row wise
There is a pivot clause concept in SQL which does that.
I am looking for it if that is available in HQL.

any suggestions please from all the members ?

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


Top
 Profile  
 
 Post subject: Re: Data as column titles
PostPosted: Fri Feb 15, 2013 11:48 am 
Newbie

Joined: Thu Feb 14, 2013 10:04 am
Posts: 4
Great !
I am getting that done.
Looking forward to see your second part of the solution ;)
TKS !


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