Skip to content

Commit

Permalink
Do not (incorrectly) set the value of @GeneratedValue IDs in tests
Browse files Browse the repository at this point in the history
It causes failures on ORM 6.6, because that's forbidden.
Previous behavior is unclear but at the very least wasn't clearly
defined.

See https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/topic/EntityManager.2Emerge/near/447248421
  • Loading branch information
yrodiere committed Jun 28, 2024
1 parent 7ff6d80 commit f9cf7cc
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

Expand All @@ -24,7 +22,6 @@ public class Group {
private String value;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "groupSeq")
public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ void shouldCreateHal() {
void shouldCreateAndUpdate() {
Response createResponse = given().accept("application/json")
.and().contentType("application/json")
.and().body("{\"id\": \"101\", \"name\": \"test-update-create\"}")
.when().put("/crud-and-paged-records/101")
.and().body("{\"name\": \"test-update-create\"}")
.when().post("/crud-and-paged-records/")
.thenReturn();
assertThat(createResponse.statusCode()).isEqualTo(201);

Expand All @@ -370,8 +370,8 @@ void shouldCreateAndUpdate() {
void shouldCreateAndUpdateHal() {
Response createResponse = given().accept("application/hal+json")
.and().contentType("application/json")
.and().body("{\"id\": \"102\", \"name\": \"test-update-create-hal\"}")
.when().put("/crud-and-paged-records/102")
.and().body("{\"name\": \"test-update-create-hal\"}")
.when().post("/crud-and-paged-records/")
.thenReturn();
assertThat(createResponse.statusCode()).isEqualTo(201);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ void shouldCreateHal() {
void shouldCreateAndUpdate() {
Response createResponse = given().accept("application/json")
.and().contentType("application/json")
.and().body("{\"id\": \"101\", \"name\": \"test-update-create\"}")
.when().put("/jpa-records/101")
.and().body("{\"name\": \"test-update-create\"}")
.when().post("/jpa-records/")
.thenReturn();
assertThat(createResponse.statusCode()).isEqualTo(201);

Expand All @@ -370,8 +370,8 @@ void shouldCreateAndUpdate() {
void shouldCreateAndUpdateHal() {
Response createResponse = given().accept("application/hal+json")
.and().contentType("application/json")
.and().body("{\"id\": \"102\", \"name\": \"test-update-create-hal\"}")
.when().put("/jpa-records/102")
.and().body("{\"name\": \"test-update-create-hal\"}")
.when().post("/jpa-records/")
.thenReturn();
assertThat(createResponse.statusCode()).isEqualTo(201);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ void shouldCreateHal() {
void shouldCreateAndUpdate() {
Response createResponse = given().accept("application/json")
.and().contentType("application/json")
.and().body("{\"id\": \"101\", \"name\": \"test-update-create\"}")
.when().put("/default-records/101")
.and().body("{\"name\": \"test-update-create\"}")
.when().post("/default-records/")
.thenReturn();
assertThat(createResponse.statusCode()).isEqualTo(201);

Expand All @@ -177,8 +177,8 @@ void shouldCreateAndUpdate() {
void shouldCreateAndUpdateHal() {
Response createResponse = given().accept("application/hal+json")
.and().contentType("application/json")
.and().body("{\"id\": \"102\", \"name\": \"test-update-create-hal\"}")
.when().put("/default-records/102")
.and().body("{\"name\": \"test-update-create-hal\"}")
.when().post("/default-records/")
.thenReturn();
assertThat(createResponse.statusCode()).isEqualTo(201);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void shouldCreateUpdateAndDeleteBook() {
Response response = given().accept("application/json")
.and().contentType("application/json")
.and().body(book.toString())
.when().put("/books/100")
.when().post("/books/")
.thenReturn();
assertThat(response.statusCode()).isEqualTo(201);
assertThat(response.header("Location")).isNotEmpty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package io.quarkus.it.spring.data.jpa.complex;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class Parent extends ParentBase {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

public Parent(Long id, String name, String detail, int age, float test, TestEnum testEnum) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package io.quarkus.it.spring.data.jpa.complex;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class Parent2 extends ParentBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

public Parent2(String name, String detail, int age, float test, TestEnum testEnum, Long id) {
Expand Down

0 comments on commit f9cf7cc

Please sign in to comment.