JPA无法在SQL Server中调用用户定义的函数

时间:2017-10-30 11:51:16

标签: java sql-server hibernate jpa

我从之前的查询SQL server query returns but function does not获得了成功,

USE [darshandb]
GO
DROP FUNCTION [dbo].[testfunction]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
    CREATE FUNCTION [dbo].[testfunction] (@empId INT,@siteId INT)
     RETURNS TABLE
     WITH SCHEMABINDING
     AS
     RETURN
     (
      WITH treeResult(id) AS 
        (SELECT pt.id FROM myschema.art_artwork_tree AS pt WHERE pt.id in 
          (select node_id from myschema.art_brand_user_mapping where emp_id = $empId)
         UNION ALL 
         SELECT pa.id FROM treeResult AS p, myschema.art_artwork_tree AS pa 
         WHERE pa.parent_node = p.id and pa.site_id = $siteId) SELECT id FROM treeResult AS n
    );
GO

SELECT * FROM [dbo].[testfunction] (4,3);//show list of id

我的目标是在我的function查询中调用此用户定义的JPQL。为此,我尝试了以下步骤:

1。select a from Address a where nodeId in dbo.testfunction(4,3); //无效,但类似的事情在Postgres

中工作正常
  

引起:javax.persistence.PersistenceException:org.hibernate.exception.SQLGrammarException:找不到列“dbo”或用户定义的函数或聚合“dbo.testfunction”,或者名称不明确。

2. select a from Address a where nodeId in (select id from dbo.testfunction(4,3)); //无法正常工作

  

引起:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:(

3. select a from Address a,dbo.testfunction(4,3) b where a.nodeId=b.id //无法正常工作

  

引起:org.hibernate.hql.internal.ast.QuerySyntaxException:意外令牌:(

参考链接,

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.Splitfn", or the name is ambiguous

请建议。

0 个答案:

没有答案