Skip missing indexes in <list>

I have a List that is mapped by

    <list cascade="save-update,delete,delete-orphan" inverse="true" lazy="true" name="genericIngredients">
      <key column="CHARGE_ID" not-null="true"/>
      <list-index column="CHARGE_POS"/>
      <one-to-many class="com.kobolde.rmm.jar.charge.GenericIngredient"/>
    </list>

When we get the list, it has NULLs in it. This is likely due to gaps in the values of the index column. Until we have time to do a thorough cleaning of the database, is there an option we can set to have missing numbers be skipped instead of inserting NULL in the list?

We’re using Java 11 and Hibernate 5.6.10

No, that’s not possible, as that would mean data would have to be changed. You can filter out nulls in a @PostLoad listener within the entity though.

When you say “data must be changed”, you’re referring to values in the index column?

Anyway, thanks for the solution. How do I add a PostLoad using HBM?

If the list [0=null,1=Obj1] should have nulls filtered out, it would turn to [0=Obj1] which means Hibernate has to remove the row with index 0 and change the index 1 to 0, hence data has to be changed.
Note though, that if you do this filtering yourself in a @PostLoad listener, the collection is “dirty” and the data changes I described will be flushed on transaction commit. Here you can find information on entity listeners: Hibernate ORM 5.6.12.Final User Guide

Well, it’s something we want to be written back and it saves us having to do it on deletes. Thanks again for the help, I guess I didn’t read the guide well enough.