SpringData JPA左联接SubQuery

时间:2018-08-22 10:01:48

标签: mysql spring-data-jpa

select sm.* 
from   system_mail sm 
left join (SELECT u.mail_code 
           from   user_mail u 
           where u.to_user = 1 ) um 
on sm.mail_id = um.mail_code 
where um.id is null.

此SQL在mysql中运行良好,但在SpringData JPA中出错,如何在springdata jpa中使用它?enter image description here

1 个答案:

答案 0 :(得分:1)

您应该尝试强制使用DB Engine通过nativeQuery = true运行SQL:

@Query(nativeQuery = true, value="...yourqueryhere...")