/** * Return whether the given Hibernate Session will always hold the same * JDBC Connection. This is used to check whether the transaction manager * can safely prepare and clean up the JDBC Connection used for a transaction. * <p>Default implementation checks the Session's connection release mode * to be "on_close". Unfortunately, this requires casting to SessionImpl, * as of Hibernate 3.1. If that cast doesn't work, we'll simply assume * we're safe and return {@code true}. * @param session the Hibernate Session to check * @see org.hibernate.impl.SessionImpl#getConnectionReleaseMode() * @see org.hibernate.ConnectionReleaseMode#ON_CLOSE */ protected boolean isSameConnectionForEntireSession(Session session) { if (!(session instanceof SessionImpl)) { // The best we can do is to assume we're safe. return true; } ConnectionReleaseMode releaseMode = ((SessionImpl) session).getConnectionReleaseMode(); return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode); }
/** * Return whether the given Hibernate Session will always hold the same * JDBC Connection. This is used to check whether the transaction manager * can safely prepare and clean up the JDBC Connection used for a transaction. * <p> * Default implementation checks the Session's connection release mode to be "on_close". * Unfortunately, this requires casting to SessionImpl, as of Hibernate 3.1. If that cast doesn't * work, we'll simply assume we're safe and return <code>true</code>. * * @param session the Hibernate Session to check * @see org.hibernate.impl.SessionImpl#getConnectionReleaseMode() * @see org.hibernate.ConnectionReleaseMode#ON_CLOSE */ protected boolean isSameConnectionForEntireSession(Session session) { if (!(session instanceof SessionImpl)) { // The best we can do is to assume we're safe. return true; } ConnectionReleaseMode releaseMode = ((SessionImpl) session).getConnectionReleaseMode(); return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode); }