I've refactored StatefulPersistenceContext#registerInsertedKey and StatefulPersistenceContext#wasInsertedDuringTransaction to use HashSet instead of ArrayList.
Pull Request: https://github.com/hibernate/hibernate-orm/pull/3456