Skip to content

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

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

Closed
odrotbohm opened this issue Feb 4, 2022 · 7 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@odrotbohm
Copy link
Member

odrotbohm commented Feb 4, 2022

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:

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 4, 2022
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Feb 4, 2022
@jhoeller jhoeller self-assigned this Feb 4, 2022
@jhoeller
Copy link
Contributor

jhoeller commented Feb 4, 2022

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.

@jhoeller jhoeller removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 4, 2022
@jhoeller jhoeller changed the title Read-only transactions not supported on Hibernate 6 HibernateJpaDialect compatibility with Hibernate 6 (read-only transactions etc) Feb 4, 2022
@jhoeller jhoeller added this to the 5.3.16 milestone Feb 4, 2022
@odrotbohm
Copy link
Member Author

odrotbohm commented Feb 4, 2022

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
Copy link
Contributor

jhoeller commented Feb 4, 2022

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 :-)

@jhoeller jhoeller modified the milestones: 5.3.16, 6.0.0-M3 Feb 4, 2022
@jhoeller
Copy link
Contributor

jhoeller commented Feb 4, 2022

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
Copy link
Member Author

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
Copy link
Contributor

jhoeller commented Feb 4, 2022

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
Copy link
Member Author

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
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants