Home Tweek performance of JPA OneToMany
Reply: 0

Tweek performance of JPA OneToMany

user1890 Published in July 21, 2018, 1:43 pm

I have following JPA entity:


@Table(name = "todo")
@NamedEntityGraph(name = "TodoEntity.children",
        attributeNodes = @NamedAttributeNode("children"))
public class TodoEntity {

    public TodoEntity() {

    private Long id;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Long userId;

    private String text;

    private String description;

    private Boolean collapsed;

    private Boolean completed;

    private Integer sortOrder;

    private Date expiredDate;

    private Date creationDate;

    private Integer priority;

    private String guid;

    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Column(updatable = false,nullable = false)
    private Long parentId;

    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "parentId", referencedColumnName = "id")
    @OrderBy("sortOrder ASC")
    private List<TodoEntity> children;


@EntityGraph(value = "TodoEntity.children", type = EntityGraph.EntityGraphType.FETCH)
    Page<TodoEntity> findByUserIdAndParentId(Long userId, Long parentId, Pageable pageable);

I want to have a TodoList that I can infinitely nest. The code is working so far - only thing is that when I have around 1500 todos and they are nested, SQL and the queries are becoming slow (around 1,3s)

How can I improve this?


Actually I think it would be enough to just get all Todos in the database with one query (that takes 2,2 ms) and then nesting them with java (having the parentId) so that the workload is on the application layer.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296455 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO