I have a native Mysql
query
select tl_id,c_name,m_name,u_first_name,t_name,
tl_logged_at,tl_minutes,tl_description
from users inner join clients on u_id=c_frn_owner_id
inner join matters on m_frn_client_id = c_id
inner join tasks on t_frn_matter_id = m_id
inner join task_logs on tl_frn_task_id = t_id
where c_id =2 and m_id=4 and t_id= 3 and u_id = 4
for which I can write JPQL
instead of native query. But how to get the same query using JPA Specification
, since the columns or fields in the where
conditions c_id
, m_id
, t_id
and u_id
are optionals. They are filter options provided to the user.
Generation of native query can be done using if
conditions. But they are prone to typo and SQL Injections
.
The documentation of JPASpecification
has no informations related to joining multiple tables.
Spring Official JPA Specification Doc
I am very new to JPASpecification
so any guidance will be valuable.