How to limit a collection in an Object's property in hibernate?

后端 未结 3 699
离开以前
离开以前 2021-01-25 19:24

I have two entities: item, and bid, each item have many bids for it, so bid is a collection property of item.

in the page that show an item, I just want to show the firs

3条回答
  •  不思量自难忘°
    2021-01-25 19:31

    you can use criteria's setFirstResult() and setMaxResult(). or this post would be helpful for your question

    example:

    sessionFactory.getCurrentSession().createQuery("your query here").setFirstResult(0).setMaxResult(10);
    

    this will generate 10 rows of data from database

    you have use annotation driven. simply add the annotation Size to your bid object

        @OneToMany( mappedBy = "object", cascade = CascadeType.ALL)
        @Size(min=1, max=10)
        private Set    bid;
    

提交回复
热议问题