diff --git a/documentation/src/main/asciidoc/introduction/Interacting.adoc b/documentation/src/main/asciidoc/introduction/Interacting.adoc index ed8378d72518..9dbb91aaa9f8 100644 --- a/documentation/src/main/asciidoc/introduction/Interacting.adoc +++ b/documentation/src/main/asciidoc/introduction/Interacting.adoc @@ -233,6 +233,27 @@ entityManager.getTransaction().setRollbackOnly(); A transaction in rollback-only mode will be rolled back when it completes. +[[outside-transaction]] +.💀 Using the session with no transaction 💀 +**** +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. + +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_, +- 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. + +If you think you want to actually _write_ to the database️ with autocommit enabled 🏴‍☠️🏴‍☠️🏴‍☠️,️ that's possible too, but you'll need to either <> the session explicitly or, even better, use a <>. +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. +**** + [[persistence-operations]] === Operations on the persistence context diff --git a/migration-guide.adoc b/migration-guide.adoc index 06a4b27004f8..e2e8429d03ce 100644 --- a/migration-guide.adoc +++ b/migration-guide.adoc @@ -181,7 +181,7 @@ Also, a key subgraph now always refers to a `Map` key, and never to an entity id We encourage migration to the use of the new JPA-standard operations. Or, alternatively, when building graphs, consider Hibernate's support for -textual link:{user-guide-url}#fetching-strategies-dynamic-fetching-entity-graph-parsing[graph parsing]. See also <>. +textual link:{user-guide-url}#fetching-strategies-dynamic-fetching-entity-graph-parsing[graph parsing]. [[removal-annotations]]