以下是MySQL查詢我使用檢索HolidayPackages for a given Hotel
:我可以將hibernate查詢語言用於未映射到表的實體嗎?
SELECT
pkg.idHolidayPackage, pkg.name
FROM
holidaypackage pkg
INNER JOIN
holidaypackagehotel hph ON pkg.idHolidayPackage = hph.idHolidayPackage
INNER JOIN
hotelroom hr ON hr.idHotelRoom = hph.idHotelRoom
WHERE
hr.idHotel = 1;
我有映射的POJO爲:
- HolidayPackage
- 酒店
- 的空房
我沒有的POJO 10。
有沒有什麼辦法可以使用Criteria API或HQL來執行SQL查詢而不需要爲HolidayPackageHotel創建一個POJO?
對於古玩,DB關係:
我用下面NamedNativeQuery:@NamedNativeQuery( \t \t名稱= 「getHolidayPackageForHotel」, \t \t查詢=「SELECT * FROM wah_schema.holidaypackage PKG INNER JOIN wah_schema.holidaypackagehotel HPH ON pkg.idHolidayPackage = HPH。 idHolidayPackage INNER JOIN wah_schema.hotelroom小時ON hr.idHotelRoom = hph.idHotelRoom WHERE hr.idHotel =:idHotel」, \t \t resultClass = HolidayPackage.class) 這似乎爲我工作,因爲返回類型:HolidayPackage.class是我定義的POJO實體。你認爲這種方法有什麼缺點嗎? – brainydexter 2012-03-20 09:05:13
在任何查詢中,** SELECT * from **不是首選方法。如果可能,請在select子句中添加列名。其餘的都很好。 – ManuPK 2012-03-20 09:41:01
我收到**列'IDHOTELROOM'找不到**如果我使用這個: SELECT DISTINCT pkg.idHolidayPackage,pkg.name,pkg.itineraryHeader FROM wah_schema.holidaypackage pkg INNER JOIN wah_schema.holidaypackagehotel hph ON pkg.idHolidayPackage = hph.idHolidayPackage INNER JOIN wah_schema.hotelroom hr ON hr.idHotelRoom = hph.idHotelRoom WHERE hr.idHotel =? – brainydexter 2012-03-20 10:08:25