Saturday, August 15, 2015

org.hibernate.AssertionFailure: possible non-threadsafe access to session

When you are using a sequence for an entity

and persist it, detach it, and merge it in a transaction,

you will get the following error:

ERROR: HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: possible non-threadsafe access to session

You should flush it before merging it.

Unfortunately I didn't understand the reason.

I'm not sure it's a bug or wrong usage.

It was just a test code and I'm not sure it could be a real scenario or not.

1 comment:

  1. Similar issue is observed when below sequence of code is executed in single transaction.
    create entity object and persist it
    create 2nd entity object and persist and detach it.

    org.hibernate.AssertionFailure :
    HHH000099:
    an assertion failure occurred
    (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session):
    org.hibernate.AssertionFailure: possible non-threadsafe access to session

    Again not sure if it's a bug or incorrect usage.

    And it is a test code and this may not be real time situation where something like this needs to be clubbed in single transaction.

    ReplyDelete