Professional Documents
Culture Documents
Hibernate in Working
access code Hibernates powerful query facilities allow you to express almost everything you commonly needed to express in SQL, but in object-oriented terms-using classes and properties of classes There are three ways to express queries in hibernate HQL, Criteria API and direct SQL
execution. It involves several distinct steps Step 1: Create a query Step2: Bind runtime arguments to query parameters Step3: Execute the prepared query against the database and retrieve data
to be used To create a new Hibernate Query instance, call either createQuery() or createSQLQuery() on a Session.
Query hqlQuery = session.createQuery(from User); Query sqlQuery = session.createSQLQuery(select * from USERS )
be retrieved in memory. Retrieving the whole result into memory is very common; called as listing
List result = myQuery.list();
Sometimes you know that the result is only a single instance. Then
Exercise
Using HQL, retrieve all the Employee objects which you
saved in the database. Using HQL, retrieve all the Employee objects whose name starts with A