vendredi 27 février 2015

How to avoid lazy fetch in JSON serialization using Spring Data JPA + Spring Web MVC?

I have a solution using Spring Data JPA and a REST Controller in Spring Web MVC. The persistence provider is Hibernate.


The persistence layer is built using Spring Repositories and between de REST Controller and the repository exists a Service Layer:



Entity <--> Repository <--> Service <--> Controller


At entity level, I have @OneToMany fields with FetchType = LAZY.


When the REST Controller make the serialization, the fetching is made, but this is undesirable in some cases.


I already tried with @JSONInclude Jackson annotation and the serialization still occurs.


Can somebody help me with a proved solution?


Aucun commentaire:

Enregistrer un commentaire