When 2PC is not used, it can be interesting to minimize the risk and flush all operations before running all the commits.
We might be able to guess that and disable the internal Hibernate flush for each session in this case,
we also could let this as a recommended pattern for users (trigger flush manually before commit)
or we could do it during transaction.commit() maybe optionally (define a flag property)
Doing everything we reasonably can to avoid a partial-success situation makes a ton of sense. How would we detect that 2PC isn't being used?
can give a clue. If it's JDBCTransactionFactory that's not 2PC
If it's CMTTransactionFactory, JoinableCMTTransactionFactory, JTATransactionFactory, the underlying resources are JTA, I imagine the Appserver/JTA coordinater will yell if more than one resource is not XA (am I correct?)
So we could try and guess based on that.
The other strategy is to ask the user to tell us through a shard property