JPA 2.0是否支持SQL Server表变量? [英] Does JPA 2.0 support SQL Server table variables?
问题描述
我正在使用JPA 2.0和SQL Server 2008,并且确定使用表变量时JPA不喜欢我的存储过程.
I am using JPA 2.0 and SQL Server 2008 and I have determined that JPA doesn't like my stored procedures when I use a table variable.
例如,此存储过程有效:
For example, this sproc works:
declare @t table
(
id int identity
, test varchar(50)
)
select 'blah' as test -- I'm ignoring the table variable above
但是,当我尝试使用此代码将某些内容插入表变量@t
时,它会崩溃:
However, when I try to insert something into the table variable @t
with this code, it crashes:
declare @t table
(
id int identity
, test varchar(50)
)
insert into @t
select cast(getdate() as varchar(60))
select * from @t
我收到以下错误:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.
Error Code: 0
如果可以帮助的话,我讨厌不得不重写我的复杂存储过程以不使用表变量.
I would hate to have to rewrite my complex sprocs to not use table variables if I can help it.
谢谢您的建议.
推荐答案
随机想法:尝试添加SET NOCOUNT ON.
Random thought: Try adding SET NOCOUNT ON.
您的代码
insert into @t
select cast(getdate() as varchar(60))
select * from @t
...将返回此
(1 row(s) affected)
id test
----------- --------------------------------------------------
1 Jun 14 2011 3:58PM
(1 row(s) affected)
SQL Server提供了实际的三个结果项目".第一个没有关联的结果集.
There are actual three result "items" from SQL Server. The first has no assoicated result set.
...以及我的问题的无耻插入使用时设置NOCOUNT ,其中提到破坏ORM之类的原因是这个
... and a shameless plug of my question SET NOCOUNT ON usage where breaking ORMs and such is mentioned because of this
这篇关于JPA 2.0是否支持SQL Server表变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!