I am using Hibernate in my application and at one place, I am trying to save many records in the same table at the same time. I << html>
These records refer to the child's parents (a child-to-one relationship for parents). Parents and children's records are saved at one time, the following code is
beats beats = new beats (); HashSet & LT; BeatMembers & gt; BeatMembersSet = NewHashcat & lt; Beat member & gt; (); String [] memberArere = bit namescript (","); For (int i = 0; i & lt; members are.lambith; i ++) {beat member member = new bitmembers (); Member.setMemberName (membersArray [i]); Member.setBeats (beat); BeatMembersSet.add (member); } Beatsset Beatmumbar (Beat MembersSet); Session.save (beat);
As you can see, I am dividing a string based on '' and I save the resulting array in many records in the database.
My problem is that the order in which the records are being saved is not the same as the order in which it is made. Is there a way to fix this?
I'm running MySQL 5.6 with Hibernate 4.3.8 and Java 1.7. *
You store your members in a hashet. A hashasset does not preserve the order of its members, instead use a LinkedHashSet or a list.