1

I am developing application which is running on WebSphere Server version 8.5.5. The application has database layer which calls 3 MS SQL function with parameters. SQL function is composed from two (max. three) join tables.

What is better?
Can I use SQL function (Java CallableStatement)? Can I white SQL SELECT(NamedQuery) direct in JPA 2.0 and do not use sql function?

I think that use SQL SELECT in JPA is clearer and cleaner. What is faster?

I think that database query(function or jpa select) is performed direct in database. It is true?

I tried JPA 2.1. on WebSphere for calling function and it was unsuccessful.

Thank you very much.

FLICKER
  • 6,439
  • 4
  • 45
  • 75
Zdenek
  • 11
  • 1
  • 4

1 Answers1

0

I think that use SQL SELECT in JPA is clearer and cleaner. What is faster?

I think that database query(function or jpa select) is performed direct in database. It is true?

It's better to use a named query to a native query, when the query string is not complicated. When taking about performance. You have to know something about what goes on under the hood. You have probably programmed something using straightforward JDBC, so you know how to queries get passed to the driver and send to the database. When using HQL or JPA-QL the queries first have to be parsed into an SQL language that the database can understand. In this case, we have an extra parsing step in between. Note that Native SQL queries, including stored procedure calls, the persistence framework still takes care of mapping the JDBC result sets to graphs of persistent objects.

I tried JPA 2.1. on WebSphere for calling function and it was unsuccessful.

You have to use a native query when calling a database function. In this case to have to take the pain to map do the mapping. See JPA : How to convert a native query result set to POJO class collection for more information.

Community
  • 1
  • 1
cdaiga
  • 4,861
  • 3
  • 22
  • 42