Hibernate Cascade


We are using Hibernate. Parent and child tables values are inserted using Cascade.

@OneToMany(cascade = CascadeType.ALL, mappedBy = "fieldname", fetch = FetchType.EAGER)

The issue we are facing is like : While sending the are values are like Item1, Item2, Item3 . But after insertion, in table it is inserted as Item2, Item1,Item3.

Which means, it is not getting in the same order as we passed through.

Any help is appreciated.


SQL does not guarantee any ordering unless you are using the ORDER BY clause.

Also, using EAGER fetching for collections is a very bad choice.

Hi Vlad,

Thanks for the reply.

Actually, while inserting into mysql, using Hibernate , the insertion of lines are not same order what we are passing.

Yes. while retrieving from the table we can use ORDER BY. But, during insertion, it is not adding in the same order as we passed.

Any suggestion on this please…

I’ve never seen what you described. Send us a Pull Request with a test case that replicate this situation: