diff --git a/pom.xml b/pom.xml index 000901260..84071a9a4 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 5.0.0-SNAPSHOT 4.0.0-SNAPSHOT - 6.5.2.Final + 7.0.0.Beta1 diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/AssignableSequenceStyleGenerator.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/AssignableSequenceStyleGenerator.java new file mode 100644 index 000000000..33ee07895 --- /dev/null +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/AssignableSequenceStyleGenerator.java @@ -0,0 +1,20 @@ +package org.springframework.data.rest.webmvc.jpa; + +import org.hibernate.id.enhanced.SequenceStyleGenerator; + +/** + * Extension to {@link SequenceStyleGenerator} to allow assigned identifiers. + * + * @author Mark Paluch + * @see Manually + * setting the identifier results in object optimistic locking failure exception + * @see HHH-17472 + */ +public class AssignableSequenceStyleGenerator extends SequenceStyleGenerator { + + @Override + public boolean allowAssignedIdentifiers() { + return true; + } +} diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/Order.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/Order.java index 36ea0b012..4bfc6db43 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/Order.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/Order.java @@ -18,7 +18,6 @@ package org.springframework.data.rest.webmvc.jpa; import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; -import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; @@ -30,13 +29,14 @@ import java.util.List; /** * @author Oliver Gierke + * @author Mark Paluch */ @Entity @Table(name = "ORDERS") public class Order { - @Id @GeneratedValue // - private Long id; + @Id + @SequenceGenerator private Long id; @ManyToOne(fetch = FetchType.LAZY) // private Person creator; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) // diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/SequenceGenerator.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/SequenceGenerator.java new file mode 100644 index 000000000..6c7d286ae --- /dev/null +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/main/java/org/springframework/data/rest/webmvc/jpa/SequenceGenerator.java @@ -0,0 +1,22 @@ +package org.springframework.data.rest.webmvc.jpa; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.hibernate.annotations.IdGeneratorType; + +/** + * Variant of {@link jakarta.persistence.GeneratedValue} using Hibernate-specific generators. + * + * @see Manually + * setting the identifier results in object optimistic locking failure exception + * @see HHH-17472 + */ +@IdGeneratorType(AssignableSequenceStyleGenerator.class) +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.FIELD }) +public @interface SequenceGenerator { +}