java - Hibernate does wrong insertion order for child entities with composite keys -


i have table relies on insertion order (bad legacy design cannot change) , having transient entities being inserted in wrong order. table in question called 'mean' child entity of 'belief'. when session.save(belief); called, action cascaded child mean entities stored list in belief class. mean entities stored in appropriate order in belief.getmeans() list, once persisted database, inserted in order of composite key. example, if there 3 mean entities inserted following order , composite keys:

[1, 1], [1, 3], [1, 2] 

they inserted ordered composite keys so:

[1, 1], [1, 2], [1, 3] 

any idea might causing this? thought hibernate supposed insert based on order appear in list? tried running session.save() on each mean entity individually see if make difference, didn't.

i appreciate help!

edit: ended doing adding new column mean table called col_index holds column index of mean in resulting matrix. used javax.persistence.orderby annotation new col_index column list of mean entities comes in appropriate order. although, still not fix insertion order problem, , still have answer that. now, solution have suffice.

i think should use @ordercolumn , not @orderby.

the @orderby annotation used when fetching collection elements order not maintained hibernate.

the @ordercolumn allows hibernate persist element collection index designated order column, used when fetching collection.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -