DB2 "With UR" Spring Data JPA - spring

I am using a Spring Data Repository interface to retrieve data from DB2 (z/OS). I have a couple of methods that rely on the method signatues and one that relies on an explicit #Query.
How do I make the SQL generated have the "WITH UR" clause?
I added #Transactional(isolation=Isolation.READ_UNCOMMITTED) on the line above the #Query annotation and also above the two methods but it doesn't seem to append the clause to the generated SQL.
Thanks

Related

Get query string from data jpa for debug

I have usually JpaRepository.
There are several types of queries in it.
made with
JPA
JPQL
HQL
It occurred to me to see if they were doing unnecessary actions. I have enabled SQL query debug. Requests began to be output to my console.
I want to write a test for queries so that they do not contain join when it is not needed.
How can I get the string that Hibernate (or Spring Data JPA) generates.
Maybe there are other ways to find such dangerous situations in the code?

Spring Boot Rest API + JPA

I have a CRUD based application, which uses Spring Boot REST Services and JPA. For JPA we have POJO objects mapped to RBMS - PostgreSQL.
Some of my pages require data to be fetched using joins of multiple POJO objects. I just wanted to know what is a good architectural practice to do the same. Following are some of the options i have been informed of, but not sure what are the pros and cons of each especially for a large data volume application.
Use Transient Variables in POJOs and use JPA joins
Use additional Spring View Objects to combine POJOs
Write native/HQL to join tables/POJOs
Any insight would be helpful. If any more details required from me, would be glad to provide.
I think it's better to go with Entity Mappings.
This will enable you to easily fetch the parent and its nested entities using either JPA methods or using hibernate.
You can also specify the fetch type to actually control the behaviour of this fetch.
In case, you are looking for any complex joins or fetch patterns, Entity Graphs and HQL will be very useful.

Using SOQL queries in Spring JPA

I have to use SOQL queries within a Spring Data Repository, Is there a way to do so by using #Query annotation ? If not is there a alternative way ?
As far as I know salesforce doesn't expose the table structures. Rather they expose their objects and you can write queries on them. spring-data-jpa is used on top of an entity framework like hibernate. Unless you have entity objects mapped to actual database tables, spring-data-jpa is not useful.
The best way would be to use a query builder like jooq and construct SOQL queries easily using query builders.

Is a Spring Data JPA #Query dynamic or named?

JPA #NamedQuery is translated to SQL only once when application is deployed and generated SQL is cached.
EntityManager.createQuery translates query every time our method is called.
What Spring-data-jpa is doing with query defined in #Query annotation? Is it translated to SQL once during deployment (like NamedQuery) or translated every time (like dynamic query) ?
Spring Data JPA calls EntityManager.createQuery(…) for every invocation of a query method annotated with #Query. The reason for that is quite simple: the Query instances returned by the EntityManager are not thread-safe and actually stateful as they contain bound parameter information.
That said, most of the JPA persistence provider perform some kind of text-based query caching anyway so that they basically build the actual SQL query once for a certain JPQL query and reuse the former on subsequent invocations.
As an interesting side note, when we started building the support for #Query in 2008 we looked into possibilities to rather register the manually declared queries as named queries with JPA. Unfortunately there wasn't - and up until today - there's no way to manually register a named query programmatically via the JPA.

JPA & JDBC can coexist in DAO layer?

Is there any problem using both JDBC (JdbcTemplate) & JPA (EntityManager) in data access layer ?
I am planning to use JDBC to access the stored-procedures/routines.
These stored-procedures will be returning multiple cursors by joining multiple tables (which is not registered as JPA entities).
These JDBC actions are pure read-only.
I am not combining JPA & JDBC actions in the same transactions as given here
It is okay for me . Use the right tools for the job . For example , if I want to do some report queries which the data are spanned over many different entities or want to use some powerful database features (eg window function , common table expression ) which are not supported or difficult to be achieved by JPA , I would prefer to use JDBC to issue native SQL directly to get the job done.
The architecture CQRS also uses this idea which has two different separate models for updating information (command action) and reading information (query action) .For example , JPA can be used for command action while native JDBC is used for the query action.

Resources