Using native Queries with Hibernate and JPA

JPA native queries allow developers to use native SQL statements in their JPA application. You can use these queries to access specific features of a database or to optimize performance by using the database’s native language.

Read more

Hibernate Query by example

With Hibernate’s and JPA powerful query facilities, you can express almost everything you typically need to express in SQL, but in object-oriented terms—using classes and properties of classes. In this article, we will show you how to create and execute a Query with JPA and the Hibernate API.

Read more

Hibernate and JPA Named Query example

This article is a walkthrough the Hibernate and JPA Named Query interface and how you can use it to externalize common Hibernate and JPA specification lets you externalize query strings to the mapping Metadata, a technique that is called named queries. This allows you to store all queries related to a particular persistent class (or … Read more

How to use native Queries in JPA ?

Native Queries are typically used to leverage some optimizations/features of your database which are not available through HQL/JPQL. Consider the following example: @Stateless public class ServiceBean { private static final String QUERY = “SELECT emp_id, name, dept_id, address_id from Employee ” + “START WITH manager_id = ? ” + “CONNECT BY PRIOR emp_id = manager_id”; … Read more

How to use ScrollableResults with Hibernate

Supposing you have to fetch a large resultset and update the single objects. By using the standard Query Object you would retrieve the whole set of Objects in Memory: Query q = session.createQuery(“from ABC”); List l = q.list(); On the other hand, if you need to operate on an online cursor, then you can use … Read more

How to call a stored procedure from Hibernate / JPA?

Let’s learn how to invoke a Stored Procedure from Hibernate and JPA applications. Supposing you have the following Oracle Stored procedure: CREATE FUNCTION agenda RETURN SYS_REFCURSOR AS my_cursor SYS_REFCURSOR; BEGIN OPEN my_cursor FOR SELECT id,person_name,person_surname,person_address FROM Person; RETURN my_cursor; END; Invoking it from Hibernate requires mapping the Stored Procedure in the Person class. <sql-query name=”SP_agenda” … Read more

How to paginate your Entity data

Returning large sets of data from your queries is an issue for many applications. It is virtually impossible to display a huge entire result in a single page so applications should be able to display a range of aresult set and provide users with the ability to control the range of data that they are … Read more

Hibernate Query Articles

List of Hibernate Query Articles   How to see the SQL generated by Hibernate Hibernate and JPA named query example Hibernate Query by example How to open an online cursor with Hibernate? Using native Queries with Hibernate and JPA How to call a stored procedure with Hibernate ? How to paginate your Entity How to … Read more