Does JPA 2.0 support SQL Server table variables?

你说的曾经没有我的故事 提交于 2019-12-18 05:21:39

问题


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

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

I get the following error:

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.

Thanks for any suggestions.


回答1:


Random thought: Try adding SET NOCOUNT ON.

Your code

insert into @t
    select cast(getdate() as varchar(60))

select * from @t

...will return this

(1 row(s) affected)
id          test
----------- --------------------------------------------------
1           Jun 14 2011  3:58PM

(1 row(s) affected)

There are actual three result "items" from SQL Server. The first has no assoicated result set.

... and a shameless plug of my question SET NOCOUNT ON usage where breaking ORMs and such is mentioned because of this



来源:https://stackoverflow.com/questions/6344631/does-jpa-2-0-support-sql-server-table-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!