Testei seu código aqui e aparentemente está funcionando normalmente, acredito que talvez você esteja fazendo a requisição de forma incorreta, por isso está recebendo nulo como resposta!
Log da aplicação inicializando e fazendo os 2 inserts no H2.
Hibernate:
insert
into
user
(id, email, name, password)
values
(null, ?, ?, ?)
Hibernate:
insert
into
user
(id, email, name, password)
values
(null, ?, ?, ?)
2023-11-09 12:01:45.615 WARN 30677 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-11-09 12:01:45.760 INFO 30677 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8090 (http) with context path ''
2023-11-09 12:01:45.765 INFO 30677 --- [ main] gusystem.api.GuApiApplication : Started GuApiApplication in 1.834 seconds (JVM running for 2.132)
2023-11-09 12:03:45.338 INFO 30677 --- [nio-8090-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-11-09 12:03:45.338 INFO 30677 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-11-09 12:03:45.340 INFO 30677 --- [nio-8090-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
Request sendo feita para recuperar os 2 registros cadastrados anteriormente:
$ curl -v -X GET "http://localhost:8090/user/1"
* Trying 127.0.0.1:8090...
* Connected to localhost (127.0.0.1) port 8090 (#0)
> GET /user/1 HTTP/1.1
> Host: localhost:8090
> User-Agent: curl/8.1.2
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 09 Nov 2023 15:03:45 GMT
<
* Connection #0 to host localhost left intact
{"id":1,"name":"gustavo","email":"[email removido]","password":"123"}%
$ curl -v -X GET "http://localhost:8090/user/2"
* Trying 127.0.0.1:8090...
* Connected to localhost (127.0.0.1) port 8090 (#0)
> GET /user/2 HTTP/1.1
> Host: localhost:8090
> User-Agent: curl/8.1.2
> Accept: */*
>
< HTTP/1.1 200
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Thu, 09 Nov 2023 15:03:51 GMT
<
* Connection #0 to host localhost left intact
{"id":2,"name":"luiz","email":"[email removido]","password":"321"}%
Em ambas requests buscando pelos Ids 1 e 2 obtive a resposta normalmente!