spring data jpa uuid转varcher

在使用JPA利用原生SQL查询数据库时,报错:No Dialect mapping for JDBC type: 1111

解决办法:

由于联表查询时需要返回多个字段,所以JPA接收数据是自定义的一个POJO,而查询返回类型中有uuid类型字段,需要利用 cast方法将uuid字段转换为varchar,例如:

SELECT A
	.*,
	B.username AS userName 
FROM
	(
	SELECT COUNT
		( ID ) AS requestsSent,
		MAX ( created_time ) AS lastRequestedTime,
		########转换一下#########
		CAST(user_id AS VARCHAR) userId
	FROM
		enroll_request 
	WHERE
		tenant_id = 'e0256650-96b0-11eb-98f9-e5d041965b26' 
	GROUP BY
		user_id 
	)
	A LEFT JOIN end_user B ON A.userId = CAST(B.ID  AS VARCHAR) 
-- WHERE
-- 	userName LIKE'%Jack%' 
ORDER BY
	lastRequestedTime DESC

来源:https://blog.csdn.net/Absosba/article/details/115751630

posted @ 2022-09-28 18:17  Lafite-1820  阅读(116)  评论(0编辑  收藏  举报