3

from what I've read in the Hibernate documentation/online it sounds like Hibernate does not have the ability to handle multiple result sets. I'm looking to make a MySQL DB call in an application that relies on Hibernate, that will return multiple result sets.

What solutions have you used that "play well" with Hibernate, keeping in mind it's likely this will be the only call where multiple result sets will be returned?

Thanks!

Ryan P.
  • 855
  • 2
  • 14
  • 20

3 Answers3

5

AFAIK, you can't handle multiple result sets with hibernate. But I don't think you need it - multiple result sets can rarely map to results like List<FooEntity>. You can use plain JDBC for the queries that return multiple result sets and handle them manually.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 1
    That's also not possible with plain JDBC at all. It returns only one resultset for each `SELECT` query as well. – BalusC Jan 29 '11 at 05:07
  • 2
    @BalusC - there is http://download.oracle.com/javase/6/docs/api/java/sql/Statement.html#getMoreResults%28%29 `Statement.getMoreResults()` - I think that gets the next result set – Bozho Jan 29 '11 at 07:58
  • Oh, stored procedures can return multiple resultsets. I've never used them though. – BalusC Jan 29 '11 at 12:44
  • @BalusC - I've never used them as well, but learnt about them when hibernate failed to handle it properly (from a legacy db) – Bozho Jan 29 '11 at 12:57
  • Thanks guys, JDBC looks to be a viable alternative. I'm working on wiring up Spring JDBC for some of the additional features. – Ryan P. Jan 31 '11 at 22:27
0

If the resultsets are coming from a stored procedure it is possible to get them using the javax.persistence.StoredProcedureQuery class. Make sure though that all resultsets consist of the exact same columns in the same order. A bug in hibernate causes it to expect all the resultsets to have the same form as the first resultset.

Maurice
  • 6,698
  • 9
  • 47
  • 104
0

I am sure you already have seen this @Ryan, but for sake of someone else (like me):

For Sybase or MS SQL server the following rules apply:

The procedure must return a result set. Note that since these servers can return multiple result sets and update counts, Hibernate will iterate the results and take the first result that is a result set as its return value. Everything else will be discarded.

From here.

javamonkey79
  • 17,443
  • 36
  • 114
  • 172