Hi,
So I have two tables called "kiosk" and "venue". A venue can have many kiosks. I want to be able to count how many kiosks are at a given venue. Now this is really simple in SQL by...
Code:
select count(*) from kIOSK_INFORMATION where venueId=2;
This returns 4 (which is the case for venueId 2).
Now using hibernate I came up with something similar to this...
Code:
Venue venue = (Venue) session.load(Venue.class, id);
int count = venue.getKiosks().size();
So this works but the SQL generated is ...
Code:
Hibernate: select venue0_.id as id7_0_, venue0_.openTimeWeekDay as openTime2_7_0_, venue0_.closeTimeWeekDay as closeTim3_7_0_, venue0_.openTimeWeekEnd as openTime4_7_0_, venue0_.closeTimeWeekEnd as closeTim5_7_0_, venue0_.businessName as business6_7_0_, venue0_.ownerName as ownerName7_0_, venue0_.venueStreetAddress1 as venueStr8_7_0_, venue0_.venueStreetAddress2 as venueStr9_7_0_, venue0_.venueCity as venueCity7_0_, venue0_.venueState as venueState7_0_, venue0_.venueZip as venueZip7_0_, venue0_.venueTel1 as venueTel13_7_0_, venue0_.venueTel2 as venueTel14_7_0_, venue0_.venueFax as venueFax7_0_, venue0_.venueEmail1 as venueEmail16_7_0_, venue0_.venueEmail2 as venueEmail17_7_0_, venue0_.venueSize as venueSize7_0_, venue0_.manager1 as manager19_7_0_, venue0_.manager2 as manager20_7_0_, venue0_.bartender1 as bartender21_7_0_, venue0_.bartender2 as bartender22_7_0_, venue0_.bartender3 as bartender23_7_0_, venue0_.bartender4 as bartender24_7_0_, venue0_.comments as comments7_0_, venue0_.installDate as install26_7_0_, venue0_.removeDate as removeDate7_0_, venue0_.operatorId as operatorId7_0_ from VENUE venue0_ where venue0_.id=?
Hibernate: select kiosks0_.venueId as venueId1_, kiosks0_.id as id1_, kiosks0_.id as id3_0_, kiosks0_.serialNumber as serialNu2_3_0_, kiosks0_.preparedBy as preparedBy3_0_, kiosks0_.containerID as containe4_3_0_, kiosks0_.usCustomsArrivalDate as usCustom5_3_0_, kiosks0_.usCustomsClearedDate as usCustom6_3_0_, kiosks0_.warehouseDeliveryDate as warehous7_3_0_, kiosks0_.preparationDate as preparat8_3_0_, kiosks0_.ipAddressUSA as ipAddres9_3_0_, kiosks0_.ipAddressUK as ipAddre10_3_0_, kiosks0_.operatorId as operatorId3_0_, kiosks0_.venueId as venueId3_0_, kiosks0_.routerId as routerId3_0_, kiosks0_.adslId as adslId3_0_, kiosks0_.model as model3_0_ from KIOSK_INFORMATION kiosks0_ where kiosks0_.venueId=?
Is there a better way to do this using the hibernate API? meaning is there a way to tell hibernate to do a count query? I know I can just use createSQLQuery but if I can get hibernate to do it directly it would be better.
Thanks for any help