Spring Data Rest adds scroll excerpt turns off lazy selection

I am new to Spring Data Rest and try to play with its basic concepts. So far, everything is working well, but a few days ago, I noticed that the application performance suddenly dropped after I posted forecasts in the business.

These are my entities, repositories and 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 everything worked fine until I added an excerpt projection to the ItemRepository @RepositoryRestResource(excerptProjection=ItemExcerpt.class)

Before I do this, when I hit http: // localhost: 9191 / categories, the Hibernate output was what I expected:

select
        category0_.id as id1_0_,
        category0_.name as name2_0_ 
    from
        category category0_

This is the result that I get after adding excerptProjection=ItemExcerpt.class

Hibernate: 
    select
        category0_.id as id1_0_,
        category0_.name as name2_0_ 
    from
        category category0_
Hibernate: 
    select
        items0_.category_id as category4_1_0_,
        items0_.id as id1_1_0_,
        items0_.id as id1_1_1_,
        items0_.category_id as category4_1_1_,
        items0_.code as code2_1_1_,
        items0_.name as name3_1_1_ 
    from
        item items0_ 
    where
        items0_.category_id=?

, @OneToMany, . - , ?

+6
1

, . , spring , . , " - , ". , spring -hateoas - . , , , . @JsonIgnore . @RestResource (exported = false) , .

0
source

Source: https://habr.com/ru/post/1016398/


All Articles