# @Batchsize annotation not working for OneToMany

**URL:** <https://discourse.hibernate.org/t/batchsize-annotation-not-working-for-onetomany/5140>\
**Category:** Hibernate ORM\
**Created:** [March 5, 2021, 8:14am UTC](https://discourse.hibernate.org/t/batchsize-annotation-not-working-for-onetomany/5140 "2021-03-05T08:14:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sakshi](https://avatars.discourse-cdn.com/v4/letter/s/d78d45/32.png) [@sakshi](https://discourse.hibernate.org/u/sakshi)\
**Post date:** [March 5, 2021, 8:14am UTC](https://discourse.hibernate.org/t/batchsize-annotation-not-working-for-onetomany/5140/1 "2021-03-05T08:14:42Z")

</div>

I have following classes and on annotating @BatchSize annotation it is not working and I am getting n+1 select query.

```auto
class Shipment{
  @OneToMany(fetch = FetchType.LAZY, mappedBy = order.shipment, cascade = CascadeType.ALL, 
  orphanRemoval = true)
  @BatchSize(size=20)
  Set<Orders> orders = new HashSet(); <---- Batch size annotation not working 
  }

```

Order.class

```auto
class Order{
  @ToString.Exclude
  @ManyToOne(fetch = FetchType.LAZY , optional = false)
  @JoinColumn(name = "item_fk")
  @LazyToOne(value = LazyToOneOption.NO_PROXY)
  Item item;

  @ToString.Exclude
  @ManyToOne(fetch = FetchType.LAZY , optional = false)
  @JoinColumn(name = "shipment_fk")
  @LazyToOne(value = LazyToOneOption.NO_PROXY)
  Shipment shipment;
}

```

Item.class

```auto

  class Item{
     String id;
     String name;
    }

```

What is mistake in implementation that i am getting n+1 queries?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [March 8, 2021, 1:26pm UTC](https://discourse.hibernate.org/t/batchsize-annotation-not-working-for-onetomany/5140/2 "2021-03-08T13:26:04Z")

</div>

Please also post how you load the shipment, how you trigger lazy loading of the orders, and what queries are generated.
