• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does JPA not preserve order in which em.persist() is called?

 
Mike Cheung
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, just noticed something interesting here. If I run the following piece of code, by calling the commit only at the end of the list, JPA appears to be inserting the objects in random order into the database. The reason I can tell is because I have the database to create the identity column. And the object sequence id doesn't correspond to the order of the identity column.


However, if I run the following code it works. All I did is added the em.flush() at immediately after each em.persist(). Has anyone run into this issue before?
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt there's any guarantee of order on a flush matching the order of persist calls, barring anything required by dependencies.
I suspect it's a Set in the backend, which (generally) implies no ordering.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic