From 7d197329d6dd4d0e833014bed1c1b41309886db2 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Fri, 8 Sep 2023 22:58:55 +0200 Subject: [PATCH] HHH-17187 - Disallow UUIDs with a trailing 0 byte in tests Signed-off-by: Jan Schatteman --- .../circle/identity/AbstractEntity.java | 6 ++- .../circle/sequence/AbstractEntity.java | 6 ++- .../jpa/identity/AbstractEntity.java | 6 ++- .../jpa/sequence/AbstractEntity.java | 6 ++- .../nonjpa/identity/AbstractEntity.java | 6 ++- .../nonjpa/sequence/AbstractEntity.java | 6 ++- .../mapkey/MapKeyEnumeratedTest.java | 2 +- .../mapkey/SocialNetworkProfile.java | 3 +- .../annotations/enumerated/mapkey/User.java | 5 +-- .../test/annotations/id/UUIDGenerator.java | 3 +- .../id/sequences/UUIDGenerator.java | 3 +- .../annotations/embedded/EmbeddedTest.java | 4 +- .../association/OneToOneAssociationTest.java | 9 ++-- .../ExtendedAssociationManagementTest.java | 7 +-- .../basic/FinalFieldEnhancementTest.java | 4 +- .../cascade/CascadeWithFkConstraintTest.java | 7 +-- .../proxy/batch/AbstractBatchingTest.java | 4 +- .../DiscriminatorColumnFetchGraphTest.java | 9 ++-- .../orm/test/id/uuid/GeneratedValueTest.java | 3 ++ .../UuidGeneratorAnnotationTests.java | 4 ++ .../UUIDBasedIdInterpretationTest.java | 3 +- .../uuid/sqlrep/sqlbinary/UUIDBinaryTest.java | 3 ++ .../id/uuid/strategy/CustomStrategyTest.java | 4 ++ .../insertordering/InsertOrderingRCATest.java | 18 ++++---- ...tOrderingWithCompositeTypeAssociation.java | 8 ++-- .../JoinedSubclassBatchingTest.java | 10 ++--- .../cascade/multicircle/AbstractEntity.java | 6 ++- .../orm/test/jpa/graphs/EntityGraphTest.java | 6 +-- ...rsistAndQueryingInSameTransactionTest.java | 6 +-- .../orm/test/jpa/query/NonWhereQueryTest.java | 5 ++- .../orm/test/loaders/HqlSelectTest.java | 3 +- .../orm/test/loaders/SqlSelectTest.java | 8 ++-- ...ctionalOneToOneWithConverterEagerTest.java | 7 +-- ...ectionalOneToOneWithConverterLazyTest.java | 7 +-- .../temporals/GeneratedUuidTests.java | 3 +- .../UuidCustomGeneratedValueTest.java | 3 ++ .../identifier/UuidGeneratedValueTest.java | 4 +- .../naturalid/SimpleNaturalIdTests.java | 3 +- .../OneToOneWithEmbeddedIdTest.java | 6 +-- .../test/pagination/DistinctSelectTest.java | 7 +-- .../StoredProcedureParameterTypeTest.java | 4 +- ...eTableAliasInSubqueryWithEmbeddedTest.java | 5 ++- .../test/query/joinfetch/JoinResultTests.java | 5 +-- .../test/sql/results/ResultsShapeTests.java | 4 +- .../orm/test/tenantuuid/TenantUuidTest.java | 6 ++- .../orm/test/type/H2JsonListTest.java | 5 ++- .../orm/test/type/UUIDTypeConverterTest.java | 14 +++--- ...rsionedBidirectionalOneToOneMergeTest.java | 6 ++- .../util/uuid/SafeRandomUUIDGenerator.java | 44 +++++++++++++++++++ .../uuid/SafeRandomUUIDGeneratorTest.java | 28 ++++++++++++ 50 files changed, 233 insertions(+), 111 deletions(-) create mode 100644 hibernate-testing/src/main/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGenerator.java create mode 100644 hibernate-testing/src/test/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGeneratorTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/identity/AbstractEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/identity/AbstractEntity.java index bda717065c..0c8fd08c2c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/identity/AbstractEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/identity/AbstractEntity.java @@ -8,7 +8,9 @@ package org.hibernate.orm.test.annotations.cascade.circle.identity; import java.io.Serializable; import java.util.Date; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; @@ -32,7 +34,7 @@ public abstract class AbstractEntity implements Serializable { public AbstractEntity() { super(); - uuid = UUID.randomUUID().toString(); + uuid = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); created = new Date(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/sequence/AbstractEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/sequence/AbstractEntity.java index 1b38a5ca5a..2ff2f94c72 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/sequence/AbstractEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/circle/sequence/AbstractEntity.java @@ -8,7 +8,9 @@ package org.hibernate.orm.test.annotations.cascade.circle.sequence; import java.io.Serializable; import java.util.Date; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; @@ -32,7 +34,7 @@ public abstract class AbstractEntity implements Serializable { public AbstractEntity() { super(); - uuid = UUID.randomUUID().toString(); + uuid = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); created = new Date(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/identity/AbstractEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/identity/AbstractEntity.java index 774b164c2b..8ce5a27c85 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/identity/AbstractEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/identity/AbstractEntity.java @@ -8,7 +8,9 @@ package org.hibernate.orm.test.annotations.cascade.multicircle.jpa.identity; import java.io.Serializable; import java.util.Date; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; @@ -30,7 +32,7 @@ public abstract class AbstractEntity implements Serializable { public AbstractEntity() { super(); - uuid = UUID.randomUUID().toString(); + uuid = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); created = new Date(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/sequence/AbstractEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/sequence/AbstractEntity.java index aae43bf27e..c01cdc9a19 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/sequence/AbstractEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/jpa/sequence/AbstractEntity.java @@ -8,7 +8,9 @@ package org.hibernate.orm.test.annotations.cascade.multicircle.jpa.sequence; import java.io.Serializable; import java.util.Date; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; @@ -32,7 +34,7 @@ public abstract class AbstractEntity implements Serializable { public AbstractEntity() { super(); - uuid = UUID.randomUUID().toString(); + uuid = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); created = new Date(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/identity/AbstractEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/identity/AbstractEntity.java index c5b13a5194..dcf9b1941c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/identity/AbstractEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/identity/AbstractEntity.java @@ -8,7 +8,9 @@ package org.hibernate.orm.test.annotations.cascade.multicircle.nonjpa.identity; import java.io.Serializable; import java.util.Date; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; @@ -30,7 +32,7 @@ public abstract class AbstractEntity implements Serializable { public AbstractEntity() { super(); - uuid = UUID.randomUUID().toString(); + uuid = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); created = new Date(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/sequence/AbstractEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/sequence/AbstractEntity.java index 4123cec50e..46db5b26b5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/sequence/AbstractEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cascade/multicircle/nonjpa/sequence/AbstractEntity.java @@ -8,7 +8,9 @@ package org.hibernate.orm.test.annotations.cascade.multicircle.nonjpa.sequence; import java.io.Serializable; import java.util.Date; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; @@ -32,7 +34,7 @@ public abstract class AbstractEntity implements Serializable { public AbstractEntity() { super(); - uuid = UUID.randomUUID().toString(); + uuid = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); created = new Date(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java index 1585cceae9..cc17747cd2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/MapKeyEnumeratedTest.java @@ -25,7 +25,7 @@ public class MapKeyEnumeratedTest extends BaseCoreFunctionalTestCase { public void testMapKeyEnumerated() { Session s = openSession(); s.beginTransaction(); - User user = new User(SocialNetwork.STUB_NETWORK_NAME, "facebookId"); + User user = new User("User1", SocialNetwork.STUB_NETWORK_NAME, "facebookId"); s.save( user ); s.getTransaction().commit(); s.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/SocialNetworkProfile.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/SocialNetworkProfile.java index cbac0829bc..a91644abd8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/SocialNetworkProfile.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/SocialNetworkProfile.java @@ -24,8 +24,6 @@ import jakarta.persistence.UniqueConstraint; @Table(name = "social_network_profile", uniqueConstraints = {@UniqueConstraint(columnNames = {"social_network", "network_id"})}) public class SocialNetworkProfile { @jakarta.persistence.Id - @jakarta.persistence.GeneratedValue(generator = "system-uuid") - @org.hibernate.annotations.GenericGenerator(name = "system-uuid", strategy = "uuid2") @jakarta.persistence.Column(name = "id", unique = true) private String id; @@ -44,6 +42,7 @@ public class SocialNetworkProfile { } protected SocialNetworkProfile(User user, SocialNetwork socialNetworkType, String networkId) { + this.id = "snp_" + networkId + "_" + user.getId(); this.user = user; this.socialNetworkType = socialNetworkType; this.networkId = networkId; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/User.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/User.java index a25a083d76..45e2f99ce3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/User.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/enumerated/mapkey/User.java @@ -26,8 +26,6 @@ import java.util.Map; @Table( name = "USER_TABLE" ) public class User { @jakarta.persistence.Id - @jakarta.persistence.GeneratedValue(generator = "system-uuid") - @org.hibernate.annotations.GenericGenerator(name = "system-uuid", strategy = "uuid2") @jakarta.persistence.Column(name = "id", unique = true) private String id; @@ -39,7 +37,8 @@ public class User { protected User() { } - public User(SocialNetwork sn, String socialNetworkId) { + public User(String id, SocialNetwork sn, String socialNetworkId) { + this.id = id; SocialNetworkProfile profile = new SocialNetworkProfile(this, sn, socialNetworkId); socialNetworkProfiles.put(sn, profile); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/UUIDGenerator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/UUIDGenerator.java index b56a7db47b..7cc029dd64 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/UUIDGenerator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/UUIDGenerator.java @@ -12,6 +12,7 @@ import java.util.UUID; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.IdentifierGenerator; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; /** * Unlike Hibernate's UUID generator. This avoids @@ -24,7 +25,7 @@ import org.hibernate.id.IdentifierGenerator; public class UUIDGenerator implements IdentifierGenerator { @Override public Object generate(SharedSessionContractImplementor session, Object entity) throws HibernateException { - UUID uuid = UUID.randomUUID(); + UUID uuid = SafeRandomUUIDGenerator.safeRandomUUID(); String sud = uuid.toString(); System.out.println("uuid="+uuid); sud = sud.replaceAll("-", ""); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/UUIDGenerator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/UUIDGenerator.java index aebfbdf90e..cf89d37f1c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/UUIDGenerator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/UUIDGenerator.java @@ -12,6 +12,7 @@ import java.util.UUID; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.IdentifierGenerator; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; /** * Unlike Hibernate's UUID generator. This avoids @@ -24,7 +25,7 @@ import org.hibernate.id.IdentifierGenerator; public class UUIDGenerator implements IdentifierGenerator { @Override public Object generate(SharedSessionContractImplementor session, Object entity) throws HibernateException { - UUID uuid = UUID.randomUUID(); + UUID uuid = SafeRandomUUIDGenerator.safeRandomUUID(); String sud = uuid.toString(); System.out.println("uuid="+uuid); sud = sud.replaceAll("-", ""); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/EmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/EmbeddedTest.java index 2bd174b04f..e9f55760bb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/EmbeddedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/embedded/EmbeddedTest.java @@ -10,12 +10,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; -import java.util.UUID; import org.hibernate.Hibernate; import org.hibernate.Transaction; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.orm.test.bootstrap.binding.annotations.embedded.FloatLeg.RateIndex; import org.hibernate.orm.test.bootstrap.binding.annotations.embedded.Leg.Frequency; import org.hibernate.query.Query; @@ -772,7 +772,7 @@ public class EmbeddedTest { scope.inTransaction( session -> { Book b = new Book(); - b.setIsbn( UUID.randomUUID().toString() ); + b.setIsbn( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ); b.setSummary( new Summary() ); b = (Book) session.merge( b ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/association/OneToOneAssociationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/association/OneToOneAssociationTest.java index 2ea16f9018..cd47f2e2dd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/association/OneToOneAssociationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/association/OneToOneAssociationTest.java @@ -15,7 +15,8 @@ import org.junit.runner.RunWith; import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; /** * @author Luis Barreiro @@ -26,7 +27,7 @@ public class OneToOneAssociationTest { @Test public void test() { User user = new User(); - user.setLogin( UUID.randomUUID().toString() ); + user.setLogin( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ); Customer customer = new Customer(); customer.setUser( user ); @@ -37,7 +38,7 @@ public class OneToOneAssociationTest { EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" ); User anotherUser = new User(); - anotherUser.setLogin( UUID.randomUUID().toString() ); + anotherUser.setLogin( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ); customer.setUser( anotherUser ); @@ -52,7 +53,7 @@ public class OneToOneAssociationTest { @Test public void testSetNull() { User user = new User(); - user.setLogin( UUID.randomUUID().toString() ); + user.setLogin( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ); Customer customer = new Customer(); customer.setUser( user ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/ExtendedAssociationManagementTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/ExtendedAssociationManagementTest.java index c71e35b8bd..f7dfc0f7a3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/ExtendedAssociationManagementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/ExtendedAssociationManagementTest.java @@ -16,7 +16,8 @@ import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.Id; import jakarta.persistence.OneToOne; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.getFieldByReflection; import static org.junit.Assert.assertEquals; @@ -30,7 +31,7 @@ public class ExtendedAssociationManagementTest { @Test public void test() { User user = new User(); - user.login = UUID.randomUUID().toString(); + user.login = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); Customer customer = new Customer(); customer.user = user; @@ -41,7 +42,7 @@ public class ExtendedAssociationManagementTest { EnhancerTestUtils.checkDirtyTracking( user, "login", "customer" ); User anotherUser = new User(); - anotherUser.login = UUID.randomUUID().toString(); + anotherUser.login = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); customer.user = anotherUser; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/FinalFieldEnhancementTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/FinalFieldEnhancementTest.java index f50082dabb..6c7ebb2b8f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/FinalFieldEnhancementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/basic/FinalFieldEnhancementTest.java @@ -10,7 +10,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.Serializable; import java.util.Objects; -import java.util.UUID; import jakarta.persistence.Embeddable; import jakarta.persistence.Embedded; import jakarta.persistence.EmbeddedId; @@ -19,6 +18,7 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import org.hibernate.annotations.Immutable; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -172,7 +172,7 @@ public class FinalFieldEnhancementTest extends BaseCoreFunctionalTestCase { private String name; public EntityWithEmbeddedIdWithFinalField() { - this.id = EmbeddableId.of( UUID.randomUUID().toString() ); + this.id = EmbeddableId.of( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ); } public EmbeddableId getId() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java index aec3dda5da..73381c8918 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/cascade/CascadeWithFkConstraintTest.java @@ -21,7 +21,8 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import java.util.HashSet; import java.util.Set; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; @@ -95,7 +96,7 @@ public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase { Set cars = new HashSet<>(); Garage() { - id = UUID.randomUUID().toString(); + id = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); } void insert(Car aCar) { @@ -111,7 +112,7 @@ public class CascadeWithFkConstraintTest extends BaseCoreFunctionalTestCase { String id; Car() { - id = UUID.randomUUID().toString(); + id = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); } } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/proxy/batch/AbstractBatchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/proxy/batch/AbstractBatchingTest.java index f9a6379bcf..d6f3e0d03b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/proxy/batch/AbstractBatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/enhancement/lazy/proxy/batch/AbstractBatchingTest.java @@ -6,7 +6,6 @@ */ package org.hibernate.orm.test.bytecode.enhancement.lazy.proxy.batch; -import java.util.UUID; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; @@ -19,6 +18,7 @@ import org.hibernate.Hibernate; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; @@ -40,7 +40,7 @@ import static org.junit.Assert.assertThat; @RunWith(BytecodeEnhancerRunner.class) @CustomEnhancementContext({ NoDirtyCheckEnhancementContext.class }) public abstract class AbstractBatchingTest extends BaseNonConfigCoreFunctionalTestCase { - protected String childName = UUID.randomUUID().toString(); + protected String childName = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); protected Long parentId; @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/DiscriminatorColumnFetchGraphTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/DiscriminatorColumnFetchGraphTest.java index 79dfc50012..ca1df0e854 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/DiscriminatorColumnFetchGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/DiscriminatorColumnFetchGraphTest.java @@ -1,13 +1,12 @@ package org.hibernate.orm.test.entitygraph; import java.util.List; -import java.util.UUID; import org.hibernate.Hibernate; import org.hibernate.jpa.SpecHints; -import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.Jpa; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,7 +38,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; DiscriminatorColumnFetchGraphTest.Behaviour.class } ) -@TestForIssue(jiraKey = "HHH-15622") +@JiraKey(value = "HHH-15622") public class DiscriminatorColumnFetchGraphTest { @BeforeEach @@ -84,7 +83,7 @@ public class DiscriminatorColumnFetchGraphTest { @Id @GeneratedValue(strategy = AUTO) - private UUID id; + private Long id; @MapsId @OneToOne(fetch = FetchType.LAZY, optional = false) @@ -123,7 +122,7 @@ public class DiscriminatorColumnFetchGraphTest { @Id @GeneratedValue(strategy = AUTO) - private UUID id; + private Long id; @OneToOne(mappedBy = "behaviour", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) private Animal animal; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/GeneratedValueTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/GeneratedValueTest.java index 10685350cd..87b5457b58 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/GeneratedValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/GeneratedValueTest.java @@ -20,12 +20,14 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.UUIDGenerator; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.RootClass; import org.hibernate.testing.orm.junit.BaseUnitTest; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.hibernate.testing.util.ServiceRegistryUtil; import org.junit.jupiter.api.Test; @@ -39,6 +41,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * @author Steve Ebersole */ @BaseUnitTest +@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "Skipped for Sybase to avoid problems with UUIDs potentially ending with a trailing 0 byte") public class GeneratedValueTest { @Test public void testGeneratedUuidId() throws Exception { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/annotation/UuidGeneratorAnnotationTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/annotation/UuidGeneratorAnnotationTests.java index f5e2a3f440..badf0d2220 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/annotation/UuidGeneratorAnnotationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/annotation/UuidGeneratorAnnotationTests.java @@ -6,6 +6,7 @@ */ package org.hibernate.orm.test.id.uuid.annotation; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Property; @@ -13,12 +14,15 @@ import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModelScope; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @DomainModel( annotatedClasses = {TheEntity.class, TheOtherEntity.class} ) @SessionFactory +@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, + reason = "Skipped for Sybase to avoid problems with UUIDs potentially ending with a trailing 0 byte") public class UuidGeneratorAnnotationTests { @Test public void verifyModel(DomainModelScope scope) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java index 15524e7773..1b874f2f8b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/interpretation/UUIDBasedIdInterpretationTest.java @@ -17,6 +17,7 @@ import org.hibernate.dialect.MariaDBDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.dialect.VarcharUUIDJdbcType; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.mapping.PersistentClass; import org.hibernate.type.BasicType; import org.hibernate.type.descriptor.java.UUIDJavaType; @@ -76,7 +77,7 @@ public class UUIDBasedIdInterpretationTest { @RequiresDialect(H2Dialect.class) public void testBinaryRuntimeUsage(SessionFactoryScope scope) { scope.inTransaction( session -> { - session.byId( UuidIdEntity.class ).load( UUID.randomUUID() ); + session.byId( UuidIdEntity.class ).load( SafeRandomUUIDGenerator.safeRandomUUID() ); } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java index 34e43e6c0e..e59b38b77e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/sqlrep/sqlbinary/UUIDBinaryTest.java @@ -11,6 +11,7 @@ import java.util.UUID; import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.dialect.PostgreSQLDialect; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.persister.entity.EntityPersister; @@ -36,6 +37,8 @@ import static org.hamcrest.MatcherAssert.assertThat; @DomainModel(annotatedClasses = { UUIDBinaryTest.Node.class }) @SessionFactory @SkipForDialect(dialectClass = PostgreSQLDialect.class, reason = "Postgres has its own UUID type") +@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, + reason = "Skipped for Sybase to avoid problems with UUIDs potentially ending with a trailing 0 byte") public class UUIDBinaryTest { private static class UUIDPair { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/strategy/CustomStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/strategy/CustomStrategyTest.java index 2317c852cd..8fa0746c44 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/strategy/CustomStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/id/uuid/strategy/CustomStrategyTest.java @@ -13,10 +13,12 @@ import jakarta.persistence.Id; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; @@ -32,6 +34,8 @@ import static org.hamcrest.MatcherAssert.assertThat; annotatedClasses = CustomStrategyTest.Node.class ) @SessionFactory +@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, + reason = "Skipped for Sybase to avoid problems with UUIDs potentially ending with a trailing 0 byte") public class CustomStrategyTest { @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingRCATest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingRCATest.java index 6f1664b912..9cd35def32 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingRCATest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingRCATest.java @@ -8,10 +8,12 @@ package org.hibernate.orm.test.insertordering; import org.hibernate.cfg.Environment; import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider; +import org.hibernate.testing.orm.junit.DialectFeatureCheck; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; import org.junit.Test; import jakarta.persistence.CascadeType; @@ -34,13 +36,11 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.mockito.Mockito.verify; -@TestForIssue(jiraKey = "HHH-16485") -@RequiresDialectFeature(DialectChecks.SupportsJdbcDriverProxying.class) +@JiraKey(value = "HHH-16485") +@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsJdbcDriverProxying.class) public class InsertOrderingRCATest extends BaseNonConfigCoreFunctionalTestCase { private PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); @@ -1306,16 +1306,16 @@ public class InsertOrderingRCATest extends BaseNonConfigCoreFunctionalTestCase { } @MappedSuperclass public static abstract class BaseEntity implements Serializable { - private UUID id; + private Long id; @Id @Column(name = "f_id") @GeneratedValue - public UUID getId() { + public Long getId() { return id; } - public void setId(UUID id) { + public void setId(Long id) { this.id = id; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingWithCompositeTypeAssociation.java b/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingWithCompositeTypeAssociation.java index d06fb3fb21..b868fce20c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingWithCompositeTypeAssociation.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/insertordering/InsertOrderingWithCompositeTypeAssociation.java @@ -6,7 +6,6 @@ */ package org.hibernate.orm.test.insertordering; -import java.util.UUID; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; @@ -20,6 +19,7 @@ import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; @@ -55,10 +55,10 @@ public class InsertOrderingWithCompositeTypeAssociation { // entity associated in the embeddable takes insert priority over the parent Book entity. scope.inTransaction( entityManager -> { Book bookNoComment = new Book(); - bookNoComment.setId( UUID.randomUUID().toString() ); + bookNoComment.setId( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ); Book bookWithComment = new Book(); - bookWithComment.setId( UUID.randomUUID().toString() ); + bookWithComment.setId( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ); bookWithComment.setIntermediateObject( new IntermediateObject( new Comment( "This is a comment" ) ) ); entityManager.persist( bookNoComment ); @@ -114,7 +114,7 @@ public class InsertOrderingWithCompositeTypeAssociation { } Comment(String comment) { - this.id = UUID.randomUUID().toString(); + this.id = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); this.comment = comment; } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java index 1cace2ad69..36a13f5f42 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java @@ -11,11 +11,10 @@ import java.math.BigDecimal; import org.hibernate.ScrollMode; import org.hibernate.ScrollableResults; -import org.hibernate.annotations.GenericGenerator; import org.hibernate.cfg.Environment; -import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; @@ -27,7 +26,6 @@ import jakarta.persistence.Embeddable; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; @@ -38,7 +36,7 @@ import jakarta.persistence.ManyToOne; * * @author dcebotarenco */ -@TestForIssue(jiraKey = "HHH-2558") +@JiraKey(value = "HHH-2558") @DomainModel( annotatedClasses = { JoinedSubclassBatchingTest.Person.class, @@ -90,7 +88,7 @@ public class JoinedSubclassBatchingTest { scope.inTransaction( s -> { for ( int i = 0; i < nEntities; i++ ) { Employee e = new Employee(); - e.getId(); + e.setId( "Employee " + i ); e.setName( "Mark" ); e.setTitle( "internal sales" ); e.setSex( 'M' ); @@ -240,8 +238,6 @@ public class JoinedSubclassBatchingTest { public static class Person { @Id - @GeneratedValue(generator = "system-uuid") - @GenericGenerator(name = "system-uuid", strategy = "uuid2") private String id; @Column(nullable = false, length = 80) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/multicircle/AbstractEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/multicircle/AbstractEntity.java index 9397bf81ed..8a3896832c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/multicircle/AbstractEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/cascade/multicircle/AbstractEntity.java @@ -8,7 +8,9 @@ package org.hibernate.orm.test.jpa.cascade.multicircle; import java.io.Serializable; import java.util.Date; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Basic; import jakarta.persistence.Column; import jakarta.persistence.GeneratedValue; @@ -29,7 +31,7 @@ public abstract class AbstractEntity implements Serializable { public AbstractEntity() { super(); - uuid = UUID.randomUUID().toString(); + uuid = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); created = new Date(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/graphs/EntityGraphTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/graphs/EntityGraphTest.java index 3674e20026..da9addd06c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/graphs/EntityGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/graphs/EntityGraphTest.java @@ -12,7 +12,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -37,6 +36,7 @@ import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Root; import org.hibernate.Hibernate; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.TestForIssue; @@ -345,7 +345,7 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - String authorName = UUID.randomUUID().toString(); + String authorName = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); Set authorIds = IntStream.range(0, 3) .mapToObj(v -> { Author author = new Author(authorName); @@ -391,7 +391,7 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); - String authorName = UUID.randomUUID().toString(); + String authorName = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); Set authorIds = IntStream.range(0, 3) .mapToObj(v -> { Author author = new Author(authorName); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/PersistAndQueryingInSameTransactionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/PersistAndQueryingInSameTransactionTest.java index 2e827a4002..a09168fe66 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/PersistAndQueryingInSameTransactionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/orphan/onetomany/PersistAndQueryingInSameTransactionTest.java @@ -2,10 +2,10 @@ package org.hibernate.orm.test.jpa.orphan.onetomany; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import org.hibernate.annotations.Cascade; import org.hibernate.annotations.CascadeType; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.DialectFeatureChecks; @@ -52,7 +52,7 @@ public class PersistAndQueryingInSameTransactionTest { @Test public void testSelectingThePersistedEntity(SessionFactoryScope scope) { - String parentId = UUID.randomUUID().toString(); + String parentId = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); scope.inTransaction( session -> { Child child = new Child(); @@ -93,7 +93,7 @@ public class PersistAndQueryingInSameTransactionTest { @Test public void testSelectingAndModifying(SessionFactoryScope scope) { - String parentId = UUID.randomUUID().toString(); + String parentId = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); scope.inTransaction( session -> { Child child = new Child(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NonWhereQueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NonWhereQueryTest.java index 20345f8298..e21499d33b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NonWhereQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NonWhereQueryTest.java @@ -8,6 +8,9 @@ package org.hibernate.orm.test.jpa.query; import java.util.Objects; import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -104,7 +107,7 @@ public class NonWhereQueryTest { public AbstractEntity() { super(); - this.uuid = UUID.randomUUID(); + this.uuid = SafeRandomUUIDGenerator.safeRandomUUID(); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/HqlSelectTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/HqlSelectTest.java index 1d0fd6858b..4636ba3102 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/HqlSelectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/HqlSelectTest.java @@ -10,6 +10,7 @@ import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import org.hibernate.annotations.HQLSelect; import org.hibernate.dialect.SybaseASEDialect; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; @@ -83,7 +84,7 @@ public class HqlSelectTest { @Column(name = "Uuid_id") Long id; - java.util.UUID uuid = java.util.UUID.randomUUID(); + java.util.UUID uuid = SafeRandomUUIDGenerator.safeRandomUUID(); boolean deleted = false; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/SqlSelectTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/SqlSelectTest.java index 712bcca0c3..6ffb8a874f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/SqlSelectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/loaders/SqlSelectTest.java @@ -11,6 +11,8 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.SqlResultSetMapping; import jakarta.persistence.Table; import org.hibernate.annotations.SQLSelect; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; @@ -30,9 +32,9 @@ public class SqlSelectTest { void test(SessionFactoryScope scope) { WithSqlSelect withSqlSelect = new WithSqlSelect(); withSqlSelect.name = "Hibernate"; - withSqlSelect.uuids.add( UUID.randomUUID() ); - withSqlSelect.uuids.add( UUID.randomUUID() ); - withSqlSelect.uuids.add( UUID.randomUUID() ); + withSqlSelect.uuids.add( SafeRandomUUIDGenerator.safeRandomUUID() ); + withSqlSelect.uuids.add( SafeRandomUUIDGenerator.safeRandomUUID() ); + withSqlSelect.uuids.add( SafeRandomUUIDGenerator.safeRandomUUID() ); scope.inTransaction( s -> s.persist( withSqlSelect ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterEagerTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterEagerTest.java index bf2c2e506b..d268797192 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterEagerTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterEagerTest.java @@ -7,7 +7,8 @@ package org.hibernate.orm.test.mapping.converted.converter.onetoone; import java.io.Serializable; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.jdbc.SQLStatementInspector; import org.hibernate.testing.orm.junit.DomainModel; @@ -45,11 +46,11 @@ public class BidirectionalOneToOneWithConverterEagerTest { public void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { BarEntity bar = new BarEntity(); - bar.setBusinessId( new BusinessId( UUID.randomUUID().toString() ) ); + bar.setBusinessId( new BusinessId( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ) ); bar.setaDouble( 0.5 ); FooEntity foo = new FooEntity(); - foo.setBusinessId( new BusinessId( UUID.randomUUID().toString() ) ); + foo.setBusinessId( new BusinessId( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ) ); foo.setName( "foo_name" ); foo.setBar( bar ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterLazyTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterLazyTest.java index 7d2d832b39..981a1cd78a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterLazyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/onetoone/BidirectionalOneToOneWithConverterLazyTest.java @@ -7,7 +7,8 @@ package org.hibernate.orm.test.mapping.converted.converter.onetoone; import java.io.Serializable; -import java.util.UUID; + +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.jdbc.SQLStatementInspector; import org.hibernate.testing.orm.junit.DomainModel; @@ -45,11 +46,11 @@ public class BidirectionalOneToOneWithConverterLazyTest { public void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { BarEntity bar = new BarEntity(); - bar.setBusinessId( new BusinessId( UUID.randomUUID().toString() ) ); + bar.setBusinessId( new BusinessId( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ) ); bar.setaDouble( 0.5 ); FooEntity foo = new FooEntity(); - foo.setBusinessId( new BusinessId( UUID.randomUUID().toString() ) ); + foo.setBusinessId( new BusinessId( SafeRandomUUIDGenerator.safeRandomUUIDAsString() ) ); foo.setName( "foo_name" ); foo.setBar( bar ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java index ffa8070e14..5ebaaae701 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/GeneratedUuidTests.java @@ -22,6 +22,7 @@ import org.hibernate.annotations.ValueGenerationType; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.EventType; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.tuple.GenerationTiming; import org.hibernate.generator.BeforeExecutionGenerator; @@ -102,7 +103,7 @@ public class GeneratedUuidTests { @Override public Object generate(SharedSessionContractImplementor session, Object owner, Object currentValue, EventType eventType) { - return UUID.randomUUID(); + return SafeRandomUUIDGenerator.safeRandomUUID(); } } //end::mapping-generated-custom-ex3[] diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidCustomGeneratedValueTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidCustomGeneratedValueTest.java index 7e624987f8..a78960ffe5 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidCustomGeneratedValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidCustomGeneratedValueTest.java @@ -13,8 +13,10 @@ import jakarta.persistence.Id; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; @@ -23,6 +25,7 @@ import static org.junit.Assert.assertNotNull; /** * @author Vlad Mihalcea */ +@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "Skipped for Sybase to avoid problems with UUIDs potentially ending with a trailing 0 byte") public class UuidCustomGeneratedValueTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidGeneratedValueTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidGeneratedValueTest.java index 8f17a57557..edab3202a2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidGeneratedValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/identifier/UuidGeneratedValueTest.java @@ -10,10 +10,11 @@ import java.util.UUID; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import jakarta.persistence.Table; +import org.hibernate.dialect.SybaseDialect; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; @@ -23,6 +24,7 @@ import static org.junit.Assert.assertNotNull; /** * @author Vlad Mihalcea */ +@SkipForDialect( dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "Skipped for Sybase to avoid problems with UUIDs potentially ending with a trailing 0 byte") public class UuidGeneratedValueTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/SimpleNaturalIdTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/SimpleNaturalIdTests.java index d254d3c071..ab0d8704af 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/SimpleNaturalIdTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/naturalid/SimpleNaturalIdTests.java @@ -14,6 +14,7 @@ import javax.money.Monetary; import org.hibernate.SimpleNaturalIdLoadAccess; import org.hibernate.NaturalIdMultiLoadAccess; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.metamodel.MappingMetamodel; @@ -41,7 +42,7 @@ import static org.hamcrest.Matchers.notNullValue; @DomainModel( standardModels = StandardDomainModel.RETAIL ) @SessionFactory public class SimpleNaturalIdTests { - private static final UUID uuid = UUID.randomUUID(); + private static final UUID uuid = SafeRandomUUIDGenerator.safeRandomUUID(); @BeforeEach public void prepareTestData(SessionFactoryScope scope) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/embeddedid/OneToOneWithEmbeddedIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/embeddedid/OneToOneWithEmbeddedIdTest.java index 43790f297c..1a3a413138 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/embeddedid/OneToOneWithEmbeddedIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/onetoone/embeddedid/OneToOneWithEmbeddedIdTest.java @@ -1,9 +1,9 @@ package org.hibernate.orm.test.onetoone.embeddedid; import java.io.Serializable; -import java.util.UUID; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; @@ -96,12 +96,12 @@ class OneToOneWithEmbeddedIdTest { @Embeddable static class ID1 implements Serializable { - String id = UUID.randomUUID().toString(); + String id = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); } @Embeddable static class ID2 implements Serializable { - String id = UUID.randomUUID().toString(); + String id = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/pagination/DistinctSelectTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/pagination/DistinctSelectTest.java index 6f8e7810b4..c4df945bbd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/pagination/DistinctSelectTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/pagination/DistinctSelectTest.java @@ -8,13 +8,14 @@ package org.hibernate.orm.test.pagination; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import org.junit.Test; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.dialect.SQLServerDialect; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -47,13 +48,13 @@ public class DistinctSelectTest extends BaseCoreFunctionalTestCase { Transaction t = s.beginTransaction(); for (int i = 0; i < 5; i++) { - Tag tag = new Tag("Tag: " + UUID.randomUUID()); + Tag tag = new Tag("Tag: " + SafeRandomUUIDGenerator.safeRandomUUID()); tags.add(tag); s.save(tag); } for (int i = 0; i < NUM_OF_USERS; i++) { - Entry e = new Entry("Entry: " + UUID.randomUUID()); + Entry e = new Entry("Entry: " + SafeRandomUUIDGenerator.safeRandomUUID()); e.getTags().addAll(tags); s.save(e); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/StoredProcedureParameterTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/StoredProcedureParameterTypeTest.java index 0103073743..f4f9e787da 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/StoredProcedureParameterTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/procedure/StoredProcedureParameterTypeTest.java @@ -24,11 +24,11 @@ import java.util.Currency; import java.util.Date; import java.util.Locale; import java.util.TimeZone; -import java.util.UUID; import jakarta.persistence.ParameterMode; import javax.sql.rowset.serial.SerialBlob; import javax.sql.rowset.serial.SerialClob; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.procedure.ProcedureCall; import org.hibernate.query.TypedParameterValue; import org.hibernate.type.NumericBooleanConverter; @@ -399,7 +399,7 @@ public class StoredProcedureParameterTypeTest { scope.inTransaction( session -> session.createStoredProcedureQuery("test") .registerStoredProcedureParameter( 1, StandardBasicTypes.UUID_BINARY, ParameterMode.IN) - .setParameter( 1, UUID.randomUUID()) + .setParameter( 1, SafeRandomUUIDGenerator.safeRandomUUID()) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SameTableAliasInSubqueryWithEmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SameTableAliasInSubqueryWithEmbeddedTest.java index e20a9d830b..b8b6f96164 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SameTableAliasInSubqueryWithEmbeddedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/SameTableAliasInSubqueryWithEmbeddedTest.java @@ -9,6 +9,8 @@ package org.hibernate.orm.test.query.hql; import java.io.Serializable; import java.time.LocalDateTime; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import org.hibernate.testing.jdbc.SQLStatementInspector; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; @@ -29,7 +31,6 @@ import jakarta.persistence.Table; import jakarta.persistence.TypedQuery; import static java.util.Objects.requireNonNull; -import static java.util.UUID.randomUUID; import static org.junit.jupiter.api.Assertions.assertNotNull; /** @@ -128,7 +129,7 @@ public class SameTableAliasInSubqueryWithEmbeddedTest { private String value; public PrimaryKey() { - value = randomUUID().toString(); + value = SafeRandomUUIDGenerator.safeRandomUUIDAsString(); } public String getValue() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/joinfetch/JoinResultTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/joinfetch/JoinResultTests.java index b98b60f279..c96bfb98b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/joinfetch/JoinResultTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/joinfetch/JoinResultTests.java @@ -6,8 +6,7 @@ */ package org.hibernate.orm.test.query.joinfetch; -import java.util.UUID; - +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.internal.util.StringHelper; import org.hibernate.testing.jdbc.SQLStatementInspector; @@ -121,7 +120,7 @@ public class JoinResultTests { void createTestData(SessionFactoryScope scope) { scope.inTransaction( (session) -> { final Vendor vendor = new Vendor( 1, "ACME", "acme", "Some notes" ); - final Product product = new Product( 1, UUID.fromString( "53886a8a-7082-4879-b430-25cb94415be8" ), vendor ); + final Product product = new Product( 1, SafeRandomUUIDGenerator.safeRandomUUID(), vendor ); session.persist( vendor ); session.persist( product ); } ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/ResultsShapeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/ResultsShapeTests.java index 1e7a301ab1..72f69a08a0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/ResultsShapeTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/ResultsShapeTests.java @@ -7,13 +7,13 @@ package org.hibernate.orm.test.sql.results; import java.util.List; -import java.util.UUID; import javax.money.Monetary; import javax.money.MonetaryAmount; import jakarta.persistence.Tuple; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; import org.hibernate.query.TypedTupleTransformer; import org.hibernate.testing.orm.domain.StandardDomainModel; @@ -236,7 +236,7 @@ public class ResultsShapeTests { final Vendor acme = new Vendor( 1, "Acme, Inc.", null ); session.persist( acme ); - final Product widget = new Product( 1, UUID.randomUUID(), acme ); + final Product widget = new Product( 1, SafeRandomUUIDGenerator.safeRandomUUID(), acme ); session.persist( widget ); final SalesAssociate associate = new SalesAssociate( 1, new Name( "John", "Doe" ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/tenantuuid/TenantUuidTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/tenantuuid/TenantUuidTest.java index ce90e72d77..8fff16ddd1 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/tenantuuid/TenantUuidTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/tenantuuid/TenantUuidTest.java @@ -18,6 +18,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryProducer; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.Setting; import org.hibernate.binder.internal.TenantIdBinder; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -38,8 +40,8 @@ import static org.junit.jupiter.api.Assertions.fail; ) public class TenantUuidTest implements SessionFactoryProducer { - private static final UUID mine = UUID.randomUUID(); - private static final UUID yours = UUID.randomUUID(); + private static final UUID mine = SafeRandomUUIDGenerator.safeRandomUUID(); + private static final UUID yours = SafeRandomUUIDGenerator.safeRandomUUID(); UUID currentTenant; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/H2JsonListTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/H2JsonListTest.java index ee1f706e19..8d2eb8edc7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/H2JsonListTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/H2JsonListTest.java @@ -30,6 +30,7 @@ import jakarta.persistence.Id; import jakarta.persistence.Table; import static org.assertj.core.api.Assertions.assertThat; +import static org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator.safeRandomUUID; @SessionFactory @DomainModel( annotatedClasses = { H2JsonListTest.Path.class, H2JsonListTest.PathClob.class } ) @@ -39,8 +40,8 @@ public class H2JsonListTest { @BeforeAll public void setUp(SessionFactoryScope scope) { scope.inTransaction( session -> { - session.persist( new Path( List.of( UUID.randomUUID(), UUID.randomUUID() ) ) ); - session.persist( new PathClob( List.of( UUID.randomUUID(), UUID.randomUUID() ) ) ); + session.persist( new Path( List.of( safeRandomUUID(), safeRandomUUID() ) ) ); + session.persist( new PathClob( List.of( safeRandomUUID(), safeRandomUUID() ) ) ); } ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java index 0bca6c6674..6502be63b0 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java @@ -27,6 +27,8 @@ import jakarta.persistence.MappedSuperclass; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import static org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator.safeRandomUUID; + @DomainModel( annotatedClasses = { UUIDTypeConverterTest.Image.class, @@ -65,7 +67,7 @@ public class UUIDTypeConverterTest { ); scope.inTransaction( session -> { - image.setThumbId( UUID.randomUUID() ); + image.setThumbId( safeRandomUUID() ); session.merge( image ); session.flush(); } @@ -77,7 +79,7 @@ public class UUIDTypeConverterTest { scope.inTransaction( session -> { Image image = session.merge( new Image() ); - image.setThumbId( UUID.randomUUID() ); + image.setThumbId( safeRandomUUID() ); session.merge( image ); session.flush(); } @@ -91,7 +93,7 @@ public class UUIDTypeConverterTest { MarbleBox marbleBox = new MarbleBox( List.of( new Marble() ) ); MarbleBox saved = session.merge( marbleBox ); - saved.getMarbles().get( 0 ).setMaterialId( UUID.randomUUID() ); + saved.getMarbles().get( 0 ).setMaterialId( safeRandomUUID() ); session.merge( saved ); } ); @@ -110,7 +112,7 @@ public class UUIDTypeConverterTest { scope.inTransaction( session -> { - marbleBox.getMarbles().get( 0 ).setMaterialId( UUID.randomUUID() ); + marbleBox.getMarbles().get( 0 ).setMaterialId( safeRandomUUID() ); session.merge( marbleBox ); } ); @@ -121,7 +123,7 @@ public class UUIDTypeConverterTest { @Column(unique = true, length = 16, nullable = false) @jakarta.persistence.Id @Convert(converter = UuidBase64TypeConverter.class) - private UUID id = UUID.randomUUID(); + private UUID id = safeRandomUUID(); } @Entity(name = "Image") @@ -130,7 +132,7 @@ public class UUIDTypeConverterTest { @Column(unique = true, length = 16, nullable = false) @Convert(converter = UuidBase64TypeConverter.class) - private UUID thumbId = UUID.randomUUID(); + private UUID thumbId = safeRandomUUID(); private int position; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/version/VersionedBidirectionalOneToOneMergeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/version/VersionedBidirectionalOneToOneMergeTest.java index a142d1f870..ab44c38217 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/version/VersionedBidirectionalOneToOneMergeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/version/VersionedBidirectionalOneToOneMergeTest.java @@ -2,6 +2,8 @@ package org.hibernate.orm.test.version; import java.util.UUID; +import org.hibernate.testing.util.uuid.SafeRandomUUIDGenerator; + import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.SessionFactory; @@ -44,7 +46,7 @@ public class VersionedBidirectionalOneToOneMergeTest { @Entity(name = "TestEntity") public static class TestEntity { @Id - UUID uuid = UUID.randomUUID(); + UUID uuid = SafeRandomUUIDGenerator.safeRandomUUID(); @Version Long version; @@ -64,7 +66,7 @@ public class VersionedBidirectionalOneToOneMergeTest { @Entity(name = "AnotherTestEntity") public static class AnotherTestEntity { @Id - UUID uuid = UUID.randomUUID(); + UUID uuid = SafeRandomUUIDGenerator.safeRandomUUID(); String name; diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGenerator.java b/hibernate-testing/src/main/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGenerator.java new file mode 100644 index 0000000000..dc70af2190 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGenerator.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.testing.util.uuid; + +import java.util.UUID; + +/** + * @author Jan Schatteman + */ +public class SafeRandomUUIDGenerator { + + /** + * @return A random UUID that is guaranteed not to end with a trailing 0 byte + */ + public static UUID safeRandomUUID() { + UUID uuid = UUID.randomUUID(); + if ( !isSafeUUID(uuid) ) { + uuid = safeRandomUUID(); + } + return uuid; + } + + /** + * @return The String representation of a random UUID that is guaranteed not to end with a trailing 0 byte + */ + public static String safeRandomUUIDAsString() { + return safeRandomUUID().toString(); + } + + /** + * @param uuid The UUID to be tested + * @return true if the UUID doesn't end with a trailing 0 byte, false otherwise + */ + public static boolean isSafeUUID(UUID uuid) { + if ( uuid == null ) { + throw new RuntimeException("The UUID cannot be tested if it's null!"); + } + return ( (uuid.getLeastSignificantBits() & 0xFF) != 0 ); + } +} diff --git a/hibernate-testing/src/test/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGeneratorTest.java b/hibernate-testing/src/test/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGeneratorTest.java new file mode 100644 index 0000000000..254482b0e4 --- /dev/null +++ b/hibernate-testing/src/test/java/org/hibernate/testing/util/uuid/SafeRandomUUIDGeneratorTest.java @@ -0,0 +1,28 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.testing.util.uuid; + +import java.util.UUID; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Jan Schatteman + */ +public class SafeRandomUUIDGeneratorTest { + + @Test + public void testSafeUUIDGenerator() { + String nonZeroEnd = "53886a8a-7082-4879-b430-25cb94415be8"; + String zeroEnd = "53886a8a-7082-4879-b430-25cb94415b00"; + assertTrue( SafeRandomUUIDGenerator.isSafeUUID( UUID.fromString( nonZeroEnd )) ); + assertFalse( SafeRandomUUIDGenerator.isSafeUUID( UUID.fromString( zeroEnd )) ); + } +}