是否可以从jpa hibernate @Query
调用Oracle函数?
这对我有用:
@Query("SELECT NEW com.test.project.dto.ResultDTO(g,l.country,r.name) "
+ "FROM Items g, Service l, Service r, Service s"
+" WHERE s.id = g.id"
+" AND s.location = l.name"
+" AND s.serviceType = 'type'"
+" AND l.serviceType = 'Location'"
+" AND l.area = r.name"
+" AND r.serviceType = 'Region'")
public ResultDTO[] name();
但我想在ResultDTO
的构造函数中调用带有两个参数的Oracle函数。就像我用原生SQL做的那样。
在查询中添加:get_trans_lac(l.country, 'en')
@Query("SELECT NEW com.test.project.dto.ResultDTO(g, get_translation(l.country, 'en'),r.name) "
+ "FROM Items g, Service l, Service r, Service s"
+" WHERE s.id = g.id"
+" AND s.location = l.name"
+" AND s.serviceType = 'type'"
+" AND l.serviceType = 'Location'"
+" AND l.area = r.name"
+" AND r.serviceType = 'Region'")
public ResultDTO[] name();
有没有办法实现这个目标?
我在应用程序启动时得到了Nullpointer。
此:
SELECT NEW com.test.project.dto.ResultDTO(g, FUNCTION(get_translation, l.country, 'en'),r.name)
还提供了Nullpointer
答案 0 :(得分:0)
我自己没有尝试过,但似乎在JPQL(JPA 2.1及更高版本,JPA 2.1之前的FUNCTION(functionName, parameters, ...)
)中有一个名为FUNC
的东西,它将调用本机函数。
所以查询的第一行是:
SELECT NEW com.test.project.dto.ResultDTO(g, FUNCTION('get_translation', l.country, 'en'),r.name)