Hibernate Select Clause
In this lesson we will write example code to select the data from Insurance table using Hibernate Select Clause. The select clause picks up objects and properties to return in the query result set. Here is the query:
Select insurance.lngInsuranceId, insurance.insuranceName, insurance.investementAmount, insurance.investementDate from Insurance insurance
which selects all the rows (insurance.lngInsuranceId, insurance.insuranceName, insurance.investementAmount, insurance.investementDate) from Insurance table.
Hibernate generates the necessary sql query and selects all the records from Insurance table. Here is the code of our java file which shows how select HQL can be used:
|
To run the example select Run-> Run As -> Java Application from the menu bar. Following out is displayed in the Eclipse console:
Hibernate:
select insurance0_.ID as col_0_0_, insurance0_.insurance_name as
col_1_0_, insurance0_.invested_amount as col_2_0_,
insurance0_.investement_date as col_3_0_ from insurance insurance0_
ID: 1 Name: Car Insurance Amount: 1000 ID: 2 Name: Life Insurance Amount: 100 ID: 3 Name: Life Insurance Amount: 500 ID: 4 Name: Car Insurance Amount: 2500 ID: 5 Name: Dental Insurance Amount: 500 ID: 6 Name: Life Insurance Amount: 900 ID: 7 0 Name: Travel Insurance Amount: 2000 ID: 8 1 Name: Travel Insurance Amount: 600 ID: 9 2 Name: Medical Insurance Amount: 700 ID: 10 3 Name: Medical Insurance Amount: 900 ID: 11 4 Name: Home Insurance Amount: 800 ID: 12 5 Name: Home Insurance Amount: 750 ID: 13 6 Name: Motorcycle Insurance Amount: 900 ID: 14 7 Name: Motorcycle Insurance Amount: 780 |