Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 1
    I don't like using deprecated stuff but i guess this is a good reason to start using it. But I did not know about the Work API. Thanks very much. Commented Aug 19, 2010 at 22:23
  • 1
    Wow. I am using Hibernate 3.2.7.ga but my org.hibernate.Session does NOT have any doWork method. That's great! Commented Aug 20, 2010 at 0:48
  • 27
    yuck that is ugly. People are always going to need the raw connection for something - they should make it easy.
    – Peter
    Commented Oct 31, 2011 at 17:42
  • 11
    SessionImpl sessionImpl = (SessionImpl) session; Connection conn = sessionImpl.connection(); You can then use the connection object anywhere elese you need it in that code not just confined to a small method. Commented May 17, 2015 at 9:57
  • 2
    Even more shorter in Java8 - session.doWork(this::doSomething). If you want to return a result - use doReturningWork()
    – Optio
    Commented Jun 14, 2017 at 9:14