Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Native SQL


Native SQL allows one to utilize proprietary database SQL features such as accessing stored procedures. Furthermore, native SQL enables you to manually optimize queries using hints and specific indexes. We would expect persistence engines to continually improve their JPQL query optimization capabilities and so reduce the need to use native SQL. Unlike JPQL, native SQL is potentially database specific, so loss of portability is the cost of using it. An alternative to native SQL for database SQL is JDBC; however native SQL has the advantage of returning the results of queries as entities.

The results of a native SQL query can be one or more entity types, non-entity or scalar values, or a combination of entities and scalar values. Native SQL queries are created using the EntityManager.createNativeQuery() method. This method is overloaded and the version used depends on whether a single entity type, multiple entity types or scalar values are returned, so we will demonstrate this...