I'm in the process of upgrading to Hibernate 4 and fully implemented the Work API but am left with one issue. We have a legacy search API that needs to use the underlying connection within the Hibernate Session. How do other people deal with cases where the legacy systems require the same connection?
Code:
_session.beginTransaction(); // Need explicit control over the transaction
try {
SomeEntity entity = createEntity(); // Use session to create an entity
LegacySearchObject search = createSearch(entity); // Creates new Connection since Hibernate 4 doesn't allow us to get a handle on existing connection
SearchResults searchResults = _session.executeQuery(search); // Flushes session as expected but since search is using a different connection, it can't retrieve the uncommitted data.
assertEquals(1, searchResults.getRowCount()); // fails. No results found.
} finally {
_session.rollback();
}
This could be a serious limitation for us if I can't get a solution.
Thank you!