Java Reference
In-Depth Information
END$$
DELIMITER ;
The following code demonstrates how to execute the stored procedure
getStu-
dentsName
we just created:
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("chapter04PUM");
EntityManager em = emf.createEntityManager();
//create entity manager
StoredProcedureQuery spQuery =
em.createStoredProcedureQuery("getStudentsName",Student.class);
List<Student> results = spQuery.getResultList();
for(Student std : results)
System.out.println(std.getLastname());
New reserved identifiers
The JQPL has introduced the following new keywords:
•
ON
: This keyword allows us to make explicit joins as in SQL with the
ON
con-
dition.Before,joinsweremadewiththeliaisonattributesbetweenthetwoen-
tities, whichrequiredminimalconfiguration. Thefollowingcodedemonstrates
the use of
ON
:
String queryString = "SELECT a FROM
Student a "+" JOIN Department b ON
a.departId = b.id";
Query query = em.createQuery(queryString);
System.out.println("result :
"+query.getResultList());
•
FUNCTION
: This keyword allows you to invoke functions in your queries other
than those originally intended by JPQL (such
SUBSTRING
,
LENGTH
,
ABS
,
TRIM
, and so on). With this keyword, you can use a database function or
functions that you have defined yourself. The following query gives us the list
of students born in July by using the
month()
method of
derby database
in
order to extract the month from a birth date: