Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hibernate isolation property release_mode -> on_close not working #32556

Closed
Jeffrey-Oh opened this issue Mar 31, 2024 · 2 comments
Closed

hibernate isolation property release_mode -> on_close not working #32556

Jeffrey-Oh opened this issue Mar 31, 2024 · 2 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@Jeffrey-Oh
Copy link

Jeffrey-Oh commented Mar 31, 2024

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.4'
    id 'io.spring.dependency-management' version '1.1.4'
}

group = 'com.testtest.hibernate'
version = ''

java {
    sourceCompatibility = '17'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    // lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testCompileOnly 'org.projectlombok:lombok'
    testAnnotationProcessor 'org.projectlombok:lombok'

    // atomikos
    implementation 'com.atomikos:transactions-spring-boot3-starter:6.0.0'

    // Hibernate
    implementation group: 'com.vladmihalcea', name: 'hibernate-types-52', version: '2.9.12'
    implementation group: 'org.hibernate', name: 'hibernate-core', version: '6.2.3.Final'

    // jpa
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

    // jdbc
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'

    // mysql
    implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.27'

    implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
}

test {
    useJUnitPlatform()
}

spring:
  jpa:
    database: mysql
    database-platform: org.hibernate.dialect.MySQLDialect
    show-sql: true
    generate-ddl: false
    open-in-view: false
    hibernate:
      ddl-auto: validate
    properties:
      hibernate:
        enable_lazy_load_no_trans: true
        format_sql: true
        connection:
          handling_mode: DELAYED_ACQUISITION_AND_HOLD
          provider_disables_autocommit: false
          release_mode: on_close
        dialect: org.hibernate.dialect.MySQLDialect
      jdbc:
        order_updates: true
        batch_versioned_data: false

  main:
    allow-bean-definition-overriding: true

When migrating from the existing Spring Boot version 2.4.1 to 3.2.4, I encountered a question. When the following property is defined in hibernate-core(? or hibernate-orm) (Spring Boot version 2.4.1), it seems to be applied correctly:

spring.jpa.properties.hibernate.connection.release_mode=on_close

However, when using Hibernate-core version 6.2.3.Final in version 3.2.4 (starting from the minimum version supporting 3.x), this option is not applied, and it continues to be applied as after_statement. If I need to override the isolation property of the @Transactional annotation, the error occurs as follows because session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode().getReleaseMode() at line 92 of HibernateJpaDialect.class is not ON_CLOSE:

HibernateJpaDialect is not allowed to support custom isolation levels: make sure that its 'prepareConnection' flag is on (the default) and that the Hibernate connection release mode is set to ON_CLOSE.

Additionally, I have tested setting the value declared in PhysicalConnectionHandlingMode.class, DELAYED_ACQUISITION_AND_HOLD, as spring.jpa.properties.hibernate.connection.handling_mode=DELAYED_ACQUISITION_AND_HOLD, but the same error occurs. Is it not possible for users to control this value in the latest version? If not, could you please provide specific guidance on why this is not possible, who is responsible for calling this option, and any alternative solutions? If all of the above is an issue with the current version, I would like to request a fix.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 31, 2024
@snicoll
Copy link
Member

snicoll commented Apr 1, 2024

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Apr 1, 2024
@snicoll snicoll added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 1, 2024
@Jeffrey-Oh
Copy link
Author

Jeffrey-Oh commented Apr 1, 2024

@snicoll Thanks for your response. Upon further examination, I discovered that when the JTA configuration is set for LocalContainerEntityManagerFactoryBean, the value of session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode().getReleaseMode() on HibernateJpaDialect.class is after_statement. I think we need to check whether this option cannot be changed by the user. As you suggested, I will continue this discussion by posting a new question on Stack Overflow.

// session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode().getReleaseMode()
// -> DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setJtaDataSource(dataSource()); // dataSource() exists

// session.getJdbcCoordinator().getLogicalConnection().getConnectionHandlingMode().getReleaseMode()
// -> DELAYED_ACQUISITION_AND_HOLD
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource()); // dataSource() exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

3 participants