I have two MySQL tables with different charset UTF8(table_a) and latin1(table_b) and I would like translate the following native query to JPQL (JPA 2.1):
SELECT a.* FROM table_a a, table_b b WHERE CONVERT(a.id USING latin1) = b.a_id;
I tried the next expressions but are wrong:
@Query("SELECT a FROM tableA a, tableB WHERE FUNCTION('CONVERT', a.id USING latin) = b.aId")
@Query("SELECT a FROM tableA a, tableB WHERE FUNCTION('CONVERT', 'a.id USING latin') = b.aId")
@Query("SELECT a FROM tableA a, tableB WHERE FUNCTION('CONVERT', a.id, 'USING latin') = b.aId")
@Query("SELECT a FROM tableA a, tableB WHERE FUNCTION('CONVERT', a.id 'USING latin') = b.aId")
Is there a way to use MySQL CONVERT function with JPQL?
FUNCTIONorCONVERTkeywords, but you could addnativeQuery = trueto your@Queryin order to use native MySQL functions.@Query("SELECT a FROM tableA a, tableB WHERE FUNCTION('CONVERT', a.id USING latin) = b.aId", nativeQuery = true)nativeQuery = truewill solve the problem. See here. By usingnativeQuery, you would use your base SQL query.