Spring Boot 2.2.6 Spring Data JPA 2.2.7
Я создал объект и разместил аннотацию поля над полем. Это должно гарантировать, что тип доступа - «поле», но это не так. Если я сделаю запрос, я не получу ошибки, а ответ будет массивом с пустыми объектами. Если я помещаю соответствующий геттер в класс, то все работает. Вы видите, где я что-то забыл?
сущность
@Entity
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"})
public class Club implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
}
контроллер
@CrossOrigin
@RestController
@RequestMapping("/api")
public class ClubController {
@Autowired
private ClubRepository clubRepository;
@GetMapping("/clubs")
List<Club> getAllClubs() {
return clubRepository.findAll();
}
}
журнал
logging.level.org.hibernate = DEBUG
logging.level.org.springframework.web = DEBUG
2020-05-06 12:47:08.365 DEBUG 6379 --- [nio-8080-exec-4]
o.s.web.servlet.DispatcherServlet : GET "/api/clubs",
parameters={}
2020-05-06 12:47:08.365 DEBUG 6379 --- [nio-8080-exec-4]
s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to
com.manager.api.club.ClubController#getAllClubs()
2020-05-06 12:47:08.369 DEBUG 6379 --- [nio-8080-exec-4]
o.h.e.t.internal.TransactionImpl : On TransactionImpl
creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
2020-05-06 12:47:08.369 DEBUG 6379 --- [nio-8080-exec-4]
o.h.e.t.internal.TransactionImpl : begin
2020-05-06 12:47:08.371 DEBUG 6379 --- [nio-8080-exec-4]
o.h.q.c.internal.CriteriaQueryImpl : Rendered criteria query ->
select generatedAlias0 from Club as generatedAlias0
2020-05-06 12:47:08.371 DEBUG 6379 --- [nio-8080-exec-4]
org.hibernate.SQL :
select
club0_.id as id1_0_
from
Club club0_
Hibernate:
select
club0_.id as id1_0_
from
Club club0_
2020-05-06 12:47:08.372 DEBUG 6379 --- [nio-8080-exec-4]
org.hibernate.loader.Loader : Result set row: 0
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
org.hibernate.loader.Loader : Result row:
EntityKey[com.manager.api.club.Club#1]
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
org.hibernate.loader.Loader : Result set row: 1
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
org.hibernate.loader.Loader : Result row:
EntityKey[com.manager.api.club.Club#2]
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
o.h.engine.internal.TwoPhaseLoad : Resolving attributes for
[com.manager.api.club.Club#1]
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
o.h.engine.internal.TwoPhaseLoad : Done materializing entity
[com.manager.api.club.Club#1]
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
o.h.engine.internal.TwoPhaseLoad : Resolving attributes for
[com.manager.api.club.Club#2]
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
o.h.engine.internal.TwoPhaseLoad : Done materializing entity
[com.manager.api.club.Club#2]
2020-05-06 12:47:08.373 DEBUG 6379 --- [nio-8080-exec-4]
o.h.e.t.internal.TransactionImpl : committing
2020-05-06 12:47:08.375 DEBUG 6379 --- [nio-8080-exec-4]
m.m.a.RequestResponseBodyMethodProcessor : Using
'application/json;q=0.8', given [text/html, application/xhtml+xml,
image/webp, image/apng, application/xml;q=0.9, application/signed-
exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json,
application/*+json, application/json, application/*+json]
2020-05-06 12:47:08.376 DEBUG 6379 --- [nio-8080-exec-4]
m.m.a.RequestResponseBodyMethodProcessor : Writing
[[com.manager.api.club.Club@59ae401f,
com.manager.api.club.Club@6afd7de2]]
2020-05-06 12:47:08.379 DEBUG 6379 --- [nio-8080-exec-4]
o.s.web.servlet.DispatcherServlet : Completed 200 OK