1

I'm cleaning up some warnings, and I came up on some code using the connection() method of StatelessSession, whose deprecation doc says they missed it when deprecation the same method on Session.

Now, the answers to this question point to the doWork method on Session, but no such method exists on StatelessSession. So, how is one supposed to fix this deprecation?

Community
  • 1
  • 1
Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681

2 Answers2

0

The StatelessSession.connection() method goal was to:

Return the current JDBC connection associated with this instance.

The StatelessSession inherits this method from SessionImplementor, which is not deprecated, so it's safe to use it. Even if it's going to be removed from StatelessSession, you will still have this method from the SessionImplementor.

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • That is just not true. There's `SessionImplementor` is not inherited by `StatelessSession`. The cast might work because the class that _implements_ `StatelessSession` happens to implement `SessionImplementor` as well, but relying on such a cast is extremely brittle -- much more so than keeping the deprecated method call. – Daniel C. Sobral Mar 02 '15 at 02:50
  • You should raise this question on the Hibernate mailing list too. One option would be to have access to the current TransactionImplementator, but that's not supported yet. – Vlad Mihalcea Mar 02 '15 at 05:24
0

You can do something like this:

    StatelessSession statelessSession = HibernateUtil.getSessionFactory().openStatelessSession();
    try {
        ((StatelessSessionImpl) statelessSession).getJdbcConnectionAccess().obtainConnection().setTransactionIsolation(TRANSACTION_REPEATABLE_READ);
    } catch (SQLException e) {
        e.printStackTrace();
    }
CuteDoge
  • 109
  • 1
  • 2
  • 8