Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
membersound opened this issue Dec 17, 2024 · 1 comment
Closed

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

membersound opened this issue Dec 17, 2024 · 1 comment
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@membersound
Copy link

membersound commented Dec 17, 2024

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 17, 2024
@schauder
Copy link
Contributor

This sounds very much like a Hibernate issue, since all the JPA mapping is done by it, including the id generation.
I recommend creating a reproducer based purely on Hibernate and submitting an issue with them.

If you think this is actually a Spring Data issue, please provide a reproducer for the issue including a test case that demonstrates the correct behaviour using the EntityManager directly.

@schauder schauder closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2024
@schauder schauder self-assigned this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants