How to set up a complete tree structure using Spring Data REST and HATEOAS?

I have a JPA tree structure

@Entity public class Document { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String text; @ManyToOne @JoinColumn(name = "parent") Document parent; @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER) Set<Document> children; (getters and setters) } 

and projections

 @Projection(name = "all", types = Document.class) public interface AllDocumentsProjection { int getId(); String getText(); Set<Document> getChildren(); } 

When I make a GET request with a url

local: 8080 / documents / 1 projection = all

I get only the first children of the root document. Not children of children. Is this possible with forecasts? Or is there another way?

+4
spring-data-rest hateoas jpa tree projection
source share
3 answers

I am pretty sure that there is no way to embed resources recursively through projections . The only thing I think about manually processing this logic in the controller is: /

+1
source share
 @Projection(name = "all", types = Document.class) public interface AllDocumentsProjection { int getId(); String getText(); Set<AllDocumentsProjection> getChildren(); } 

This works great for me.

+1
source share

Try excerpts .

You must add the excerptProjection field to the storage excerptProjection , as shown below:

 @RepositoryRestResource(excerptProjection = AllDocumentsProjection.class) interface DocumentRepository extends CrudRepository<Document, Integer> {} 
-one
source share

All Articles