Skip to content

Conversation

@gavinking
Copy link
Member

[Please describe here what your change is about]


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.


@hibernate-github-bot
Copy link

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: [8ab3b0e, 67e535e]

› This message was automatically generated.

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this needs to be stated somewhere, and this looks like a good place. But I think you should tone this down, make it less personal and more detached. That won't prevent you from getting your point across IMO. I included suggestions below.

I am pretty sure we both know each other's position on such things, so I won't waste your time explaining why I feel this way and I won't ask why you do :)

Comment on lines +239 to +240
Over the years, we've run into a surprisingly large number of people who insist that they need to access the database with "no transaction" -- which we understand to mean running queries with https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setAutoCommit--[JDBC autocommit mode] enabled.
We're _pretty sure_ that this is almost always a terrible idea, and that most of the people doing this are simply mistaken about some aspect of transaction isolation or of what the use of autocommit implies for the management of pooled JDBC connections.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Over the years, we've run into a surprisingly large number of people who insist that they need to access the database with "no transaction" -- which we understand to mean running queries with https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setAutoCommit--[JDBC autocommit mode] enabled.
We're _pretty sure_ that this is almost always a terrible idea, and that most of the people doing this are simply mistaken about some aspect of transaction isolation or of what the use of autocommit implies for the management of pooled JDBC connections.
People frequently express the need to access the database with "no transaction" -- which we understand to mean running queries with https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setAutoCommit--[JDBC autocommit mode] enabled.
We're _pretty sure_ that this is almost always a terrible idea, and that most of the people doing this are simply mistaken about some aspect of transaction isolation or of what the use of autocommit implies for the management of pooled JDBC connections.

Over the years, we've run into a surprisingly large number of people who insist that they need to access the database with "no transaction" -- which we understand to mean running queries with https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setAutoCommit--[JDBC autocommit mode] enabled.
We're _pretty sure_ that this is almost always a terrible idea, and that most of the people doing this are simply mistaken about some aspect of transaction isolation or of what the use of autocommit implies for the management of pooled JDBC connections.
With that said, Hibernate grudgingly allows it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
With that said, Hibernate grudgingly allows it.
With that said, this is technically possible.

With that said, Hibernate grudgingly allows it.
If you decide to do this weird thing:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you decide to do this weird thing:
If you decide to do this despite our warnings:

If you decide to do this weird thing:
- first, satisfy yourself that you're completely comfortable with the fact that _the database will not help you enforce transaction isolation_,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- first, satisfy yourself that you're completely comfortable with the fact that _the database will not help you enforce transaction isolation_,
- first, be aware _the database will not help you enforce transaction isolation_,

- first, satisfy yourself that you're completely comfortable with the fact that _the database will not help you enforce transaction isolation_,
- then set link:{doc-javadoc-url}org/hibernate/cfg/JdbcSettings.html#AUTOCOMMIT[`hibernate.connection.autocommit=true`], and
- make damn sure that your connection pool is returning connections with autocommit enabled by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- make damn sure that your connection pool is returning connections with autocommit enabled by default.
- be extra careful to set up your connection pool so that it is returning connections with autocommit enabled by default.

- then set link:{doc-javadoc-url}org/hibernate/cfg/JdbcSettings.html#AUTOCOMMIT[`hibernate.connection.autocommit=true`], and
- make damn sure that your connection pool is returning connections with autocommit enabled by default.
In fact, simply don't do this unless you have set up tools to snoop the protocol-level interaction between the JDBC driver and the database server, so that you can verify your understanding of what "no transaction" actually implies.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not sure what kind of verifications you're asking for here.

In fact, simply don't do this unless you have set up tools to snoop the protocol-level interaction between the JDBC driver and the database server, so that you can verify your understanding of what "no transaction" actually implies.
If you think you want to actually _write_ to the database️ with autocommit enabled 🏴‍☠️🏴‍☠️🏴‍☠️,️ that's possible too, but you'll need to either <<flush,`flush()`>> the session explicitly or, even better, use a <<stateless-sessions,stateless session>>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure people know what they want better than us. They might not know what they need, though.

Suggested change
If you think you want to actually _write_ to the database️ with autocommit enabled 🏴‍☠️🏴‍☠️🏴‍☠️,️ that's possible too, but you'll need to either <<flush,`flush()`>> the session explicitly or, even better, use a <<stateless-sessions,stateless session>>.
If you think you need to actually _write_ to the database️ with autocommit enabled,️ that's possible too, but you'll need to either <<flush,`flush()`>> the session explicitly or, even better, use a <<stateless-sessions,stateless session>>.

Comment on lines +253 to +254
And don't come complaining to us when your database starts filling up with inconsistent garbage.
// Because you've now been thoroughly warned, and we're going to enjoy laughing at you.
Copy link
Member

@yrodiere yrodiere Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
And don't come complaining to us when your database starts filling up with inconsistent garbage.
// Because you've now been thoroughly warned, and we're going to enjoy laughing at you.
And keep in mind we will not address any problem resulting from this usage, such as the database filling up with inconsistent data.

Comment on lines +236 to +238
[[outside-transaction]]
.💀 Using the session with no transaction 💀
****
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use admonitions instead of emojis?

Suggested change
[[outside-transaction]]
.💀 Using the session with no transaction 💀
****
[[outside-transaction]]
[CAUTION]
.Using the session with no transaction
====

If you think you want to actually _write_ to the database️ with autocommit enabled 🏴‍☠️🏴‍☠️🏴‍☠️,️ that's possible too, but you'll need to either <<flush,`flush()`>> the session explicitly or, even better, use a <<stateless-sessions,stateless session>>.
And don't come complaining to us when your database starts filling up with inconsistent garbage.
// Because you've now been thoroughly warned, and we're going to enjoy laughing at you.
****
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If replacing with an admonition:

Suggested change
****
====

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