java - Spring Data Rest Many to many tree projection mapping -
i have entity called contentpath, may have parent of same type, , sons of same type, represented like:
@id @column(name = "id") @generatedvalue(strategy = generationtype.identity) private long id; @column(name = "name", length = 50) @notnull private string name; @column(name = "description") private string description; @manytoone @joincolumn(name="content_path_id") public contentpath contentpath; @onetomany(mappedby="contentpath") public set<contentpath> contentpaths; @manytomany(fetch = fetchtype.eager) @jointable( name = "activity_content_path", joincolumns = {@joincolumn(name = "content_path_id", referencedcolumnname = "id")}, inversejoincolumns = {@joincolumn(name = "activity_id", referencedcolumnname = "id")}) private set<activity> activities;
i have contentpathrepository, exposes api.
@repositoryrestresource(collectionresourcerel = "contentpaths", path = "contentpaths", excerptprojection = contentpathprojection.class) public interface contentpathrestrepository extends pagingandsortingrepository<contentpath, long> { }
and projection, should format correctly object.
@projection(name = "contentpathprojection", types = contentpath.class) public interface contentpathprojection { long getid(); string getname(); set<contentpath> getcontentpaths(); }
i expecting list of contentpaths, have contentpaths inside, , got success, not bringing ids, bringing name , description only, , weird because projection doesn't have description.
current response:
"name": "book 1", "id": 1, "contentpaths": [ { "name": "unit 1", "description": "unit 1 description" }, { "name": "unit 2", "description": "unit 2 description" } ]
why happening? how fix it?
this normal behavior of sdr. don't show id
default. turn on register bean this:
@bean public repositoryrestconfigureradapter repositoryrestconfigureradapter() { return new repositoryrestconfigureradapter() { @override public void configurerepositoryrestconfiguration(repositoryrestconfiguration config) { config.exposeidsfor(contentpath.class); super.configurerepositoryrestconfiguration(config); } }; }
about description
- have field:
@column(name = "description") private string description;
Comments
Post a Comment