loading - Spring Data Rest adding excerpt projection switches off lazy fetching -
i'm new spring data rest , trying play around basic concepts. works far, few days ago noticed application performance dropped after putting projections business.
these entities, repositories , projection
@entity public class item { @id @generatedvalue(strategy = table) private long id; private string code; private string name; @manytoone(targetentity=category.class) @joincolumn(name="category_id", referencedcolumnname="id") private category category; //getters & setters } @entity public class category { @id @generatedvalue(strategy = table) private long id; private string name; @onetomany(mappedby="category", targetentity=item.class, fetch=fetchtype.lazy) private set<item> items; //getters & setters } @repositoryrestresource(excerptprojection=itemexcerpt.class) public interface itemrepository extends crudrepository<item, long>{ } @repositoryrestresource public interface categoryrepository extends crudrepository<category, long>{ } @projection(name="excerpt", types=item.class) public interface itemexcerpt { string getname(); } so, worked fine untill added excerpt projection itemrepository @repositoryrestresource(excerptprojection=itemexcerpt.class)
before doing this, when hit http://localhost:9191/categories hibernate output expected be:
select category0_.id id1_0_, category0_.name name2_0_ category category0_ this output after adding excerptprojection=itemexcerpt.class
hibernate: select category0_.id id1_0_, category0_.name name2_0_ category category0_ hibernate: select items0_.category_id category4_1_0_, items0_.id id1_1_0_, items0_.id id1_1_1_, items0_.category_id category4_1_1_, items0_.code code2_1_1_, items0_.name name3_1_1_ item items0_ items0_.category_id=? my conclusion excerpt projection makes lazy fetching being ignored on @onetomany relationship, leads performance drop. know way bypass issue, or maybe expected behaviour?
Comments
Post a Comment