Skip to content

Conversation

gavinking
Copy link
Member

@gavinking gavinking commented Aug 27, 2025

Rebase of #10754


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19708

1. allow a session to be created in a read-only mode
2. pass that mode through to the MultiTenantConnectionProvider
…replica

This is better than throwing, because you might be using:

- JDBC driver-level support for replicas, together with
- true multi-tenancy
in case the MultiTenantConnectionProvider needs to access
e.g. the TenantSchemaMapper
@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Aug 27, 2025

Thanks for your pull request!

This pull request does not follow the contribution rules. Could you have a look?

❌ All commit messages should start with a JIRA issue key matching pattern HHH-\d+
    ↳ Offending commits: [8bd1595, 9c9ecf0]

› This message was automatically generated.

and remove an obsolete comment
@gavinking gavinking marked this pull request as ready for review August 27, 2025 07:13
@gavinking gavinking force-pushed the replication-2 branch 2 times, most recently from a0d3476 to 29379e8 Compare August 27, 2025 08:27
@gavinking
Copy link
Member Author

I have run into a problem here. The session often releases the connection back to the ConnectionProvider before the transaction is complete. But the Postgres driver doesn't like us calling setReadOnly() while the tx is still in progress.

@beikov
Copy link
Member

beikov commented Aug 27, 2025

Did you try moving the readOnly reset to org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor#afterTransaction already?

@gavinking
Copy link
Member Author

Did you try moving the readOnly reset to org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor#afterTransaction already?

I was looking at that option but then I realized I had kinda misdiagnosed the problem. The problem was really in the case when I didn't start any tx at all. OTOH, I'm not sure how much I care about that case. Seems to work when I do start/end a tx.

@gavinking
Copy link
Member Author

I think this is now a good-enough start to be useful for people to play around and experiment with.

Everything is marked @Incubating, and I'm not really committed to anything about the current design, and I'm totally open to changing it completely if we receive negative feedback about it. But because of the nature of this, it's going to be pretty hard to get any useful feedback before someone actually tries it out in the wild.

So I'm going to merge this. There's absolutely nothing here which is hard to roll back.

@gavinking gavinking merged commit b7591a9 into hibernate:main Aug 28, 2025
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants