Skip to content

HibernateJpaDialect compatibility with Hibernate 6 (read-only transactions etc) #28007

Closed
@odrotbohm

Description

@odrotbohm
Member

During our work to investigate the compatibility with Hibernate 6 in Spring Data JPA we ran into an issue surfacing in Spring Frameworks transaction management:

In ….beginTransaction(…), HibernateJpaDialect calls SessionImplementor.connection() a method that has been removed in CR1 (could've been in one of the betas already, I didn't check) to issue read-only transactions. It looks like the new way to access the Connection is calling ….getJdbcConnectionAccess().obtainConnection().

Related tickets:

Activity

self-assigned this
on Feb 4, 2022
jhoeller

jhoeller commented on Feb 4, 2022

@jhoeller
Contributor

We aim for a complete Hibernate 6.0 support story in our own 6.0 M3, not sure yet how far we'll go (native API via orm.hibernate6? or just with JPA? keeping up Hibernate 5.x support in parallel? etc): #22128

That said, it's definitely worth considering what we could do in 5.3.x to allow for using Hibernate 6.0 with our JPA support at least. We might want to leniently tolerate it at runtime for a start, even without full alignment yet. Let's use this ticket for it.

changed the title [-]Read-only transactions not supported on Hibernate 6[/-] [+]HibernateJpaDialect compatibility with Hibernate 6 (read-only transactions etc)[/+] on Feb 4, 2022
added this to the 5.3.16 milestone on Feb 4, 2022
odrotbohm

odrotbohm commented on Feb 4, 2022

@odrotbohm
MemberAuthor

Once I avoided read-only transactions by rather using a simple @Transactional the integration tests using Hibernate 6 CR1 on a Boot 3 M1 ran just fine. I.e. it might be just that particular issue for starters. That's why I thought I'd open the ticket around something actionable. But of course, as you see fit.

Oh, H6 is JakartaEE based. I guess that is a showstopper for any support of it in our 5.x generation.

jhoeller

jhoeller commented on Feb 4, 2022

@jhoeller
Contributor

Good point, there's no classic JPA binding for it anymore, it's exclusively built on jakarta.persistence indeed. And it won't be usable with orm.hibernate5 either due to plenty of incompatibilities in the native Hibernate API. Alright, so Hibernate ORM 6.0 becomes a Spring Framework 6.0 only topic then :-)

modified the milestones: 5.3.16, 6.0.0-M3 on Feb 4, 2022
jhoeller

jhoeller commented on Feb 4, 2022

@jhoeller
Contributor

Alright, so we'll definitely sort out HibernateJpaDialect compatibility for 6.0 M3 for a start, using this ticket. Full Hibernate 6.0 alignment - or even Hibernate 6.0 baselining - might take longer anyway, let's use #22128 for that part then.

odrotbohm

odrotbohm commented on Feb 4, 2022

@odrotbohm
MemberAuthor

I just realized that the API I found and suggested as workaround (never tested using it myself, though) also already exists in 5.6.5. I.e. we could try to just move that in 6.0 but stick to the Hibernate 5.x baseline.

jhoeller

jhoeller commented on Feb 4, 2022

@jhoeller
Contributor

It turns out that it is indeed straightforward to support both Hibernate 5.6 and 6.0 through a revision of HibernateJpaDialect where it retrieves the current JDBC connection differently. The correct replacement is getJdbcCoordinator().getLogicalConnection().getPhysicalConnection() for obtaining the current connection held by the session, as far as the connection release mode is appropriate for it. This seems to work fine on 5.6 as well as 6.0.

The other area affected is HibernateJpaVendorAdapter and its selection of default dialects for the database enum. Those dialects seem to be deprecated now, the Informix dialect is even gone completely. However, this shouldn't be a big deal since we recommend explicit Hibernate dialect configuration in any case (rather than relying on our database enum).

From that perspective, we seem to be covered in terms of JPA compatibility, so I'll close this ticket right away. The main remaining part for #22128 is whether we want/need an orm.hibernate6 package next to orm.hibernate5, or possibly as a replacement for orm.hibernate5. This mostly depends on what we are going to recommend for existing orm.hibernate5 users: staying on Hibernate 5.6, upgrading to Hibernate 6.0 via orm.hibernate6, or upgrading to Hibernate 6.0 via JPA.

odrotbohm

odrotbohm commented on Feb 8, 2022

@odrotbohm
MemberAuthor

Thanks for that, Jürgen. Verified working as expected now! 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @odrotbohm@jhoeller@spring-projects-issues

      Issue actions

        HibernateJpaDialect compatibility with Hibernate 6 (read-only transactions etc) · Issue #28007 · spring-projects/spring-framework