开发者

How do I get the resultset of a stored procedure in JPA?

I have SQL Server 2008 and a JPA (EclipseLink) app. I need to be able to read the rows from the stored procedure. The stored procedure does some updating/开发者_StackOverflow中文版etc but at the end returns a

select * from @result_table

Now, when I access it in JPA using:

String sql = "exec up_GetUpdatedRows ?, ?, ?";
entityManager = Factories.getEntityManager();

Query query = entityManager.createNativeQuery(sql);
query.setParameter(1, myKey).setParameter(2, workDate).setParameter(3, createdBy);

List<Object[]> obj = query.getResultList();

I get the following error:

Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.

This works for other native SQL.

Any ideas?

Thanks


After a lot of trial and error, I finally found this answer. I found it from another question here.

The problem was with not using SET NOCOUNT ON. It was very confusing as the error said there were no result sets. Yet, there appeared to be many.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜