# @OrderColumn broken order / null values

**URL:** <https://discourse.hibernate.org/t/ordercolumn-broken-order-null-values/3200>\
**Category:** Hibernate ORM\
**Created:** [September 9, 2019, 4:15pm UTC](https://discourse.hibernate.org/t/ordercolumn-broken-order-null-values/3200 "2019-09-09T16:15:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![beickvon](https://avatars.discourse-cdn.com/v4/letter/b/c0e974/32.png) [@beickvon](https://discourse.hibernate.org/u/beickvon)\
**Post date:** [September 9, 2019, 4:15pm UTC](https://discourse.hibernate.org/t/ordercolumn-broken-order-null-values/3200/1 "2019-09-09T16:15:21Z")

</div>

I’m using hibernate 4.2.21, but I think the issue applies to all versions.  
I have two entities Parent and Sub with a bidrectional OneToMany relation and the list is annotated with OrderColumn.

```auto
ParentJpaEntity .{
  @javax.persistence.OneToMany (fetch = FetchType.LAZY, mappedBy = "parent")
  @javax.persistence.OrderColumn (name = "ORDER")
  private java.util.List<SubJpaEntity> sub;
}

```

```auto
SubJpaEntity {
  @javax.persistence.ManyToOne (fetch = FetchType.LAZY)
  private ParentJpaEntity parent;
}

```

Now lets start with a Parent A and 10 Sub entities S0 to S9, all is fine the ORDER column contains values from 0 to 9. The issue that I’m now facing is that if I concurrently (two transactions) try to add an S10 and to null the parent attribute of S9 and removing it from the sub list at the same time.  
What happens is that S10 is added to the list and gets ORDER 10 and S9 is removed but the order is now now longer continuous, i.e. ORDER 8 is followed by ORDER 10.  
If I now retrieve the list, it will contain 11 elements with element number 10 being null.

Is this a bug or what can I do to prevent this? I use optimistic locking, i.e. both entities contain a version field, but the version of the Parent entity is never increased.
