Hibernate Query Language Example

Hibernate Query Language Example

Hibernate Query Language was created in Hibernate to support SQL as both looks similar but HQL much more powerful than SQL as it understands object structure i.e. polymorphism, inheritance, association and fully object oriented. You could use this in your java program and get data directly map to an object. Be-careful while using as its case sensitive.

Here I will show different real time example of HQL query. Let’s first create one sample table with some data:

  • Create table script:

  • Insert data script and repeat this three four time with different data:

  • Java model class mapped with Test table:

  • Select all table data:

  • Select data with where clause:

  • Select data by like clause:

  • Select data by not like clause:

  • Select data by in clause:

  • Delete data from table:

  • Update data to the table:

  • Insert data to the table: Hibernate does not support into values as we do using SQL query and her you will have to insert data from another table which is bulk insert:

download Download Project: HibernateSelectQueryExample


Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *