gpt4 book ai didi

java - 是否可以使用 jpa @Query 调用 Oracle 函数

转载 作者:太空宇宙 更新时间:2023-11-04 13:17:34 30 4
gpt4 key购买 nike

是否可以从 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 函数。就像我会使用 native 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();

有办法实现吗?

我在应用程序启动时得到一个空指针。

这个: SELECT NEW com.test.project.dto.ResultDTO(g, FUNCTION(get_translation, l.country, 'en'),r.name) 还给出一个空指针

最佳答案

我自己没有尝试过,但是JPQL(JPA 2.1及更高版本,JPA 2.1之前的FUNC)中似乎有一个名为FUNCTION(functionName,parameters, ...)的东西,它将调用 native 函数。

所以查询中的第一行是:

SELECT NEW com.test.project.dto.ResultDTO(g, FUNCTION('get_translation', l.country, 'en'),r.name)

关于java - 是否可以使用 jpa @Query 调用 Oracle 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33415612/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com