Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Hibernate

You're reading from   Mastering Hibernate Learn how to correctly utilize the most popular Object-Relational Mapping tool for your Enterprise application

Arrow left icon
Product type Paperback
Published in May 2016
Publisher Packt
ISBN-13 9781782175339
Length 204 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Native SQL

Native SQL statements are also supported in Hibernate, except you will need to use a different API call to compose a query object. There are mainly two reasons you would want to use a native SQL. The first is that you wish to use a specific feature offered by your database solution that may not be supported by Hibernate. The second is when you wish to execute an ad hoc query and store the result in an object that is not a Hibernate entity.

If you don't associate an entity with the query result, Hibernate returns the result set in a list of object array. This is known as a Scalar Query. However, you can associate an entity with the native query and Hibernate will return a list of this entity; this is known as Entity query. Let's see how these work.

Scalar query

When you execute a native SQL, the result of this query is returned in a list of object arrays. Consider the following query:

List<Object[]> objectList = session
.createSQLQuery("SELECT * FROM PERSON&quot...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image