diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java index 56e6500ab5..64c505733b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java @@ -11,6 +11,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; +import org.hibernate.HibernateError; import org.hibernate.annotations.CurrentTimestamp; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.tuple.GenerationTiming; @@ -53,6 +54,9 @@ public class MultipleGeneratedValuesTests { created.name = "first"; + //We need to wait a little to make sure the timestamps produced are different + waitALittle(); + // then changing final GeneratedInstantEntity merged = scope.fromTransaction( (session) -> { return (GeneratedInstantEntity) session.merge( created ); @@ -70,6 +74,9 @@ public class MultipleGeneratedValuesTests { assertThat( merged.createdAt2 ).isEqualTo( created.createdAt2 ); assertThat( merged.updatedAt2 ).isNotEqualTo( created.updatedAt2 ); + //We need to wait a little to make sure the timestamps produced are different + waitALittle(); + // lastly, make sure we can load it.. final GeneratedInstantEntity loaded = scope.fromTransaction( (session) -> { return session.get( GeneratedInstantEntity.class, 1 ); @@ -116,4 +123,13 @@ public class MultipleGeneratedValuesTests { this.name = name; } } + + private static void waitALittle() { + try { + Thread.sleep( 10 ); + } + catch (InterruptedException e) { + throw new HibernateError( "Unexpected wakeup from test sleep" ); + } + } }