Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use hibernate query language for entities not mapped to a table?

Following is the mySQL query that I am using to retrieve HolidayPackages for a given Hotel:

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;

I have POJOs with mapping for:

  • HolidayPackage
  • Hotel
  • HotelRoom

I don't have a POJO for HolidayPackageHotel.

Is there any way to use Criteria API or HQL to execute the sql query without creating a POJO for HolidayPackageHotel?

For the curios, DB relations: DB relations

like image 999
brainydexter Avatar asked Mar 20 '12 06:03

brainydexter


1 Answers

No. You can not use the un-mapped entities inside the HQL.

If you want to generate the List of beans from the query you can use the ResultSet transformers, which can convert the query results(object arrays) to beans. By doing this you will save the overhead of creating and filling the POJO beans.

Read here for an example.

like image 84
ManuPK Avatar answered Oct 19 '22 22:10

ManuPK