[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3220) Patch to prevent "org.hibernate.AssertionFailure: possible non-threadsafe access to the session" error caused by stateless sessions

Paul Smith (JIRA) noreply at atlassian.com
Mon Nov 28 05:09:23 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44448#comment-44448 ] 

Paul Smith commented on HHH-3220:
---------------------------------

I know this is marked as closed in 3.6.0+ however I'm hitting this _exact_ same problem with 3.6.8.Final with a InheritanceType.TABLE_PER_CLASS setup, _only_ when I issue a:

{noformat}
    Criteria criteria = statelessSession.createCriteria(com.aconex.tasks.domain.Task);
    ...
    criteria.scroll(ScrollMode.SCROLL_INSENSITIVE);
{noformat}

Which scrolls through the entire result-set, the above fails with the "non-threadsafe" error.   However issuing an effectively-the-same-query using the createQuery method with:

{noformat}
        Query query = statelessSession.createQuery("from com.aconex.tasks.domain.Task");
        ....
        query.scroll(ScrollMode.SCROLL_INSENSITIVE);
{noformat}

actually works fine.

We originally had this Query-based execution failing with the non-threadsafe error under hibernate-core 3.3.0.GA, upgraded to 3.6.8.Final to fix the problem (as is documented here), and then have needed to switch to using Criteria for more flexible partitioning of the query (parallelise the row retrievals) now to find us back with the same problem.

Switching to/from Criteria-based scrolling through the entire tablespace fails/succeeds respectively.

Is there anyone out there with advice?  I'm a bit confused as to whether the SessionWrapper class will help or not, I don't understand why a Criteria-based "select *" is executing any different than an explicit "select *" (which is what 'from <entity>' with no other criteria is right?)

Any help really appreciated, I have 130 million records I need to scroll through that I don't really want to use a stateful session.

> Patch to prevent "org.hibernate.AssertionFailure: possible non-threadsafe access to the session" error caused by stateless sessions
> -----------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-3220
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3220
>             Project: Hibernate Core
>          Issue Type: Patch
>          Components: core
>    Affects Versions: 3.2.6
>         Environment: Hibernate 3.2.6, Apache Derby on Mac OSX & PC
>            Reporter: Dan Bisalputra
>            Assignee: Strong Liu
>            Priority: Minor
>             Fix For: 3.5.3, 3.6.0.Beta1
>
>         Attachments: HibernateStatelessSessionCriteriaAssertionFailureTest.java, HibernateStatelessSessionCriteriaAssertionFailureTest.java, StatelessSession-patch
>
>
> When performing a query in a stateless session, the query loads objects in a two-phase process in which a temporary persistence context is populated with empty objects in the first phase, then the objects' member data are read from the database in the second phase.  If one of the objects contains an association or a collection, it performs a recursive call to the session's get() method.  The get() method clears the temporary persistence context, so if the parent object contains any other associations to be read in the second phase, Hibernate throws an assertion because they are not found in the persistence context.
> This patch solves the problem by only clearing the persistence context when the recursion ends.  It passes all the unit tests for our application, but I have not tested it with any of the Hibernate unit tests.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list