-->
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: Native SQL TIP: Using aggregate queries
PostPosted: Tue Dec 05, 2006 4:55 pm 
Newbie

Joined: Mon Nov 06, 2006 12:53 pm
Posts: 1
Location: Omaha
I did not see this in new book, doc or forum, so thought that I would post my expereince with Oracle.

Parent child relationship between itinerary and res_core.
The test query with a hardcoded ID is:
select
itinerary_id as ITINERARY,
sum(rc.grand_total) as TOTAL,
max(rc.total_night_stay) as NIGHTS,
min(rc.arrival_date) as ARRIVAL ,
max(rc.departure_date) as DEPARTURE
from res_core RC
where itinerary_id = 14679 and
res_type = 'L' and
reservation_status != 'C'
group by itinerary_id;
The Java is:
List result = session.createSQLQuery(
"select itinerary_id as itinerary, "+
"sum(rc.grand_total) as total, "+
"max(rc.total_night_stay) as nights, "+
"min(rc.arrival_date) as arrival, "+
"max(rc.departure_date) as departure "+
"from res_core rc "+
"where itinerary_id = 14679 and "+
" res_type = 'L' and "+
" reservation_status != 'C' group by itinerary_id" )
.addEntity(IineraryResSummary.class).list();
The Class is unsurprising:
public class IineraryResSummary implements java.io.Serializable{
private BigDecimal itinerary;
private BigDecimal total;
private BigDecimal nights;
private Date arrival;
private Date departure;
plus the standard stuff.
And the mapping file is:
<hibernate-mapping>
<class name="us.cenres.creditcard.model.IineraryResSummary" table="Iinerary_Res_Summary">
<id name="itinerary" type="big_decimal">
<column name="ITINERARY" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="total" type="big_decimal">
<column name="TOTAL" precision="5" scale="0" />
</property>
<property name="nights" type="big_decimal">
<column name="NIGHTS" precision="5" scale="0" />
</property>
<property name="arrival" type="date">
<column name="ARRIVAL" length="7" />
</property>
<property name="departure" type="date">
<column name="DEPARTURE" length="7" />
</property>
</class>
</hibernate-mapping>
[code]

Since this is a read only query, I'm assuming that the bogus table in the mapping file will not cause any problems when I move from JUnit-land to production.

Regards[/code]


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.