Skip to content

@Id GenerationType.IDENTITY fails when setting id manually #3720

@membersound

Description

@membersound

spring-boot-starter-parent-3.3.5: OK
spring-boot-starter-parent-3.4.0: FAILURE

Since boot 3.4.0, the following test fails.
Has there been a change on purpose, so that the prior behavior was actually false, and has now been corrected?
Or is this a bug?

I noticed: downgrading hibernate also fixed the issue: <hibernate.version>6.5.3.Final</hibernate.version>` (= version from boot 3.3.5)

@Entity
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long id;

    public String lastname;

    protected Person() {
        //hibernate
    }
}

@SpringBootTest
class DemoApplicationTest {
	@Autowired
	private PersonRepository dao;

	@Test
	public void testPersist() {
		Person b = new Person();
		b.id = 1L;
		b.lastname = "Doe";

		dao.save(b);
		assertEquals(1, dao.count());
	}
}

demo.zip

Sidenote: I cannot remember exactly why I was setting the ID here manually. Probably there was an issue with the generated sequence ids at time of writing.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions