It's not a bug, but a feature
Identity and Sequences are transaction-less. If they weren't, then one transaction would hold the lock, and if that transaction didn't release it for 5 minutes, no other transaction could insert any other record for the same table.
So, back to your questions:
What happens with Entities in session if I make rollback?
The entity identifier does not change at all. Now, rolling back the transaction means the flush hasn't gone through. So, while its fine to commit several consecutive transactions, if an exception is thrown and you roll back, then the Session
should be close, as the Hibernate Session
Javadoc says:
If the Session throws an exception, the transaction must be rolled back and the session discarded. The internal state of the Session might not be consistent with the database after the exception occurs.
Do they get back to the state before the transaction?
No, of course not. The auto-generated ids are not bound to the currently running transaction.