[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7212) [Envers] Avoid useless temporary session in Tools.getTargetFromProxy()

Fabien Le Bars (JIRA) noreply at atlassian.com
Mon Apr 2 12:20:49 EDT 2012


[Envers] Avoid useless temporary session in Tools.getTargetFromProxy()
----------------------------------------------------------------------

                 Key: HHH-7212
                 URL: https://hibernate.onjira.com/browse/HHH-7212
             Project: Hibernate ORM
          Issue Type: Improvement
          Components: envers
    Affects Versions: 4.1.1
         Environment: Hibernate 4.1.1.Final 
H2 1.3.165
            Reporter: Fabien Le Bars
            Priority: Trivial


The method  from Tools class : public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactoryImplementor, HibernateProxy proxy); 
uses a temporary session when the proxy is not initialized.

In some cases though, the proxy.getSession() is not null and calling directly proxy.getHibernateLazyInitializer().getImplementation() will return an initialized object even though it was uninitialized right before the call.

Thus changing the following lines 
      if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
            return proxy.getHibernateLazyInitializer().getImplementation();
        }

into:
      if (!proxy.getHibernateLazyInitializer().isUninitialized()
                || proxy.getHibernateLazyInitializer().getSession() != null) {
            return proxy.getHibernateLazyInitializer().getImplementation();
      }

avoids useless uses of the temporary session.

The reason I had to made this minor change is that H2 does not handle well temporary sessions when using in-memory database with the initializing script direcly passed in the url (when the temporary session is opening a new connection, it attemps to recreate the whole database and miserably fails).

       
   

--
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