I am concerned that there is a bug in Spring boot 3.2.x. I migrate from 2.8.x and I am encounter problem with one of the repositories for Users of my application. When I call JPA repository save() method with entity email and password are not written in to the database.
I have the following test that fails with custom exception: com.intuitionlabs.dulocart.exception.ResourceNotFoundException: Customer with that email test@email.com does not exists. The case is there no exceptions when I test it manual just the data is not saved into the database.
If you need more info I can provide.
@Test
void verifyFindByEmail() {
Customer customer = Customer.builder().email("test@email.com").build();
Customer expected = repository.save(customer);
Customer actual = service.findByEmail("test@email.com");
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getEmail(), actual.getEmail());
}
Version of Spring boot is:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.1</version>
<relativePath/>
</parent>
Repository :
@Repository
public interface CustomerRepository extends JpaRepository <Customer, Long> {
Optional<Customer> findByEmail(String email);
}
Service:
public interface CustomerService {
Customer save(Customer customer);
}
Service Implementation:
@Service
public class CustomerServiceImpl implements CustomerService {
private final CustomerRepository repository;
public CustomerServiceImpl(CustomerRepository repository) {
this.repository = repository;
}
@Override
public Customer save(Customer customer) {
return repository.save(customer);
}
Comment From: bclozel
This looks more like an issue with Hibernate and maybe Lombok or your entity class?
You can ask a question on StackOverflow or create a minimal sample application that you can share here.
Comment From: mikebgrep
Most likely Hibernate as the Lombok set the properties. I try the couple of methods for migrating, including JWT implementation. The result is that repository does not write the username and the password in the database also reproducible with H2.
https://github.com/mikebgrep/simple-spring-boot-application-reproduction
This is the reproduction application I have same behavior as explained. If you run the test should be valid.
Regards, and happy holidays.
Comment From: mannam11
@mikebgrep can i get controller method for this please..?
Comment From: bclozel
Thanks for the feedback. This indeed works with Spring Boot 2.7.x and fails starting with 3.0.x. This looks similar to https://github.com/spring-projects/spring-data-jpa/issues/2980 and as advised by the Spring Data team, you should try first to reproduce this with a pure EntityManager scenario and see if it fails. If so, you should report that to the Hibernate team (there is a known case for Kotlin, but I'm not sure this applies here at all), otherwise a Spring Data JPA issue would be more appropriate.
Comment From: mikebgrep
Thank you for the answer. I will forward it ahead.I am not sure about pure EntityManager, but with Entity that does not extend the base User.java class, the test is passing.