99import org .hibernate .Session ;
1010import org .hibernate .StaleObjectStateException ;
1111import org .hibernate .boot .registry .StandardServiceRegistryBuilder ;
12+ import org .hibernate .dialect .CockroachDialect ;
1213import org .hibernate .dialect .MySQLDialect ;
1314import org .hibernate .dialect .lock .OptimisticEntityLockException ;
1415import org .hibernate .engine .spi .SharedSessionContractImplementor ;
1516import org .hibernate .testing .orm .junit .BaseSessionFactoryFunctionalTest ;
1617import org .hibernate .testing .orm .junit .JiraKey ;
18+ import org .hibernate .testing .orm .junit .SkipForDialect ;
1719import org .junit .jupiter .api .BeforeEach ;
1820import org .junit .jupiter .api .Test ;
1921
@@ -75,6 +77,8 @@ public void testRefreshWithOptimisticLockRefresh() {
7577
7678 @ Test
7779 @ JiraKey (value = "HHH-19937" )
80+ @ SkipForDialect (dialectClass = CockroachDialect .class ,
81+ reason = "Cockroach uses SERIALIZABLE by default and seems to fail reading state that was written by a different TX that completed within this TX" )
7882 public void testRefreshWithOptimisticForceIncrementLockRefresh () {
7983 doInHibernate ( this ::sessionFactory , session -> {
8084 C c = session .find ( C .class , id , LockModeType .OPTIMISTIC_FORCE_INCREMENT );
@@ -87,6 +91,8 @@ public void testRefreshWithOptimisticForceIncrementLockRefresh() {
8791
8892 @ Test
8993 @ JiraKey (value = "HHH-19937" )
94+ @ SkipForDialect (dialectClass = CockroachDialect .class ,
95+ reason = "Cockroach uses SERIALIZABLE by default and seems to fail reading state that was written by a different TX that completed within this TX" )
9096 public void testRefreshWithOptimisticLockFailure () {
9197 assertThrows ( OptimisticEntityLockException .class , () ->
9298 doInHibernate ( this ::sessionFactory , session -> {
@@ -101,9 +107,11 @@ public void testRefreshWithOptimisticLockFailure() {
101107
102108 @ Test
103109 @ JiraKey (value = "HHH-19937" )
110+ @ SkipForDialect (dialectClass = CockroachDialect .class ,
111+ reason = "Cockroach uses SERIALIZABLE by default and seems to fail reading state that was written by a different TX that completed within this TX" )
104112 public void testRefreshWithOptimisticForceIncrementLockFailure () {
105113 // TODO: shouldn't this also be an OptimisticEntityLockException
106- assertThrows ( StaleObjectStateException .class , () ->
114+ assertThrows ( StaleObjectStateException .class /* or TransactionSerializationException */ , () ->
107115 doInHibernate ( this ::sessionFactory , session -> {
108116 C c = session .find ( C .class , id , LockModeType .OPTIMISTIC_FORCE_INCREMENT );
109117 session .refresh ( c );
0 commit comments