2 Replies Latest reply on Nov 17, 2007 4:42 AM by marklittle

    JDBC Connection

    jantzen

      I have a stateless session bean that issues select statements returning very large result sets. Therefore, it utilizes Query.setMaxResults and setFirstResult methods to page over the set, reusing the Query object. The EntityManager that creates the Query is injected by JBoss via the PersistenceContext annotion.

      While this works fine under JBoss 4.0.5, under 4.2.1 the operation fails due to the underlying Session getting closed.

      So, it appears that the EntityManager/Session is closed after the first call to Query.getResultList(), and any subsequent operations occur on a closed Session, even though the method on the stateless session bean has not yet returned. Making the bean stateful and setting the PersistenceContext to "EXTENDED" appears to enable reuse of the Query.

      Am I correct that in a stateless session bean injected PersistenceContexts may only be used once per method invocation? Is this truly the specified behavior? This is highly counter-intuitive. With stateful beans, is the Session closed and a new one assigned via dependency injection, or left open?

      Thanks

        • 1. Re: JDBC Connection
          jantzen

          Whoops, the title got truncated. I meant to say that Hibernate is reportedly "agressively closing" the JDBC connection.

          According to http://jira.jboss.com/jira/browse/HIBERNATE-32, "For an application server JTA datasource, always after_statement is used to aggressively release connections after every JDBC call".

          This seems to have the side-effect that for a stateless session bean, the rule is, one trip to the database per method invocation. Yikes. For real?

          • 2. Re: JDBC Connection
            marklittle

            Better to take this to the hibernate forums for now.