-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
doc about using Session with "no transaction" #10223
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 :)
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - 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. |
There was a problem hiding this comment.
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>>. |
There was a problem hiding this comment.
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.
| 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>>. |
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
| [[outside-transaction]] | ||
| .💀 Using the session with no transaction 💀 | ||
| **** |
There was a problem hiding this comment.
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?
| [[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. | ||
| **** |
There was a problem hiding this comment.
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:
| **** | |
| ==== |
[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.