Skip to content

Commit

Permalink
Deprecate setAllowResultAccessAfterCompletion and document it as broken
Browse files Browse the repository at this point in the history
Closes gh-26557
  • Loading branch information
jhoeller committed Jul 11, 2023
1 parent ad3e542 commit c375fb1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Expand Up @@ -97,16 +97,18 @@
* support nested transactions! Hence, do not expect Hibernate access code to
* semantically participate in a nested transaction.</i>
*
* <p><b>NOTE: Hibernate ORM 6.x is officially only supported as a JPA provider.
* Please use {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean}
* with {@link org.springframework.orm.jpa.JpaTransactionManager} there instead.</b>
*
* @author Juergen Hoeller
* @since 4.2
* @see #setSessionFactory
* @see #setDataSource
* @see SessionFactory#getCurrentSession()
* @see DataSourceUtils#getConnection
* @see DataSourceUtils#releaseConnection
* @see org.springframework.jdbc.core.JdbcTemplate
* @see org.springframework.jdbc.support.JdbcTransactionManager
* @see org.springframework.transaction.jta.JtaTransactionManager
* @see org.springframework.orm.jpa.JpaTransactionManager
* @see org.springframework.orm.jpa.vendor.HibernateJpaDialect
*/
@SuppressWarnings("serial")
public class HibernateTransactionManager extends AbstractPlatformTransactionManager
Expand Down Expand Up @@ -271,7 +273,11 @@ public void setPrepareConnection(boolean prepareConnection) {
* @see Connection#setHoldability
* @see ResultSet#HOLD_CURSORS_OVER_COMMIT
* @see #disconnectOnCompletion(Session)
* @deprecated as of 5.3.29 since Hibernate 5.x aggressively closes ResultSets on commit,
* making it impossible to rely on ResultSet holdability. Also, Spring does not provide
* an equivalent setting on {@link org.springframework.orm.jpa.JpaTransactionManager}.
*/
@Deprecated(since = "5.3.29")
public void setAllowResultAccessAfterCompletion(boolean allowResultAccessAfterCompletion) {
this.allowResultAccessAfterCompletion = allowResultAccessAfterCompletion;
}
Expand Down Expand Up @@ -487,7 +493,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {

session = txObject.getSessionHolder().getSession().unwrap(SessionImplementor.class);

boolean holdabilityNeeded = this.allowResultAccessAfterCompletion && !txObject.isNewSession();
boolean holdabilityNeeded = (this.allowResultAccessAfterCompletion && !txObject.isNewSession());
boolean isolationLevelNeeded = (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT);
if (holdabilityNeeded || isolationLevelNeeded || definition.isReadOnly()) {
if (this.prepareConnection && ConnectionReleaseMode.ON_CLOSE.equals(
Expand All @@ -500,7 +506,7 @@ protected void doBegin(Object transaction, TransactionDefinition definition) {
Integer previousIsolationLevel = DataSourceUtils.prepareConnectionForTransaction(con, definition);
txObject.setPreviousIsolationLevel(previousIsolationLevel);
txObject.setReadOnly(definition.isReadOnly());
if (this.allowResultAccessAfterCompletion && !txObject.isNewSession()) {
if (holdabilityNeeded) {
int currentHoldability = con.getHoldability();
if (currentHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) {
txObject.setPreviousHoldability(currentHoldability);
Expand Down
Expand Up @@ -66,6 +66,10 @@
* {@link HibernateTransactionManager}, this naturally allows for mixing JPA access code
* with native Hibernate access code within the same transaction.
*
* <p><b>NOTE: Hibernate ORM 6.x is officially only supported as a JPA provider.
* Please use {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean}
* with {@link org.springframework.orm.jpa.JpaTransactionManager} there instead.</b>
*
* @author Juergen Hoeller
* @since 4.2
* @see #setDataSource
Expand Down

0 comments on commit c375fb1

Please sign in to comment.