wangscript / warp-persist

Automatically exported from code.google.com/p/warp-persist
0 stars 0 forks source link

NPE in HibernateLocalTxnInterceptor #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
NPE in line 48 of HibernateLocalTxnInterceptor

Session session =
SessionFactoryHolder.getCurrentSessionFactory().getCurrentSession(); 

SessionFactoryHolder.getCurrentSessionFactory() returns null causing an NPE. 

I am using warp-persist 1.0 on Fedora Core 8. 

All of my DAOs extend a GenericHibernateDAO class with a Guice-injected
sessionProvider in the constructor (below). I am also using a setter to
intialize the Persistence service and a static boolean to ensure it only
gets called once.

GenericHibernateDAO {

        private static boolean isPersistenceServiceStarted;

    public GenericHibernateDAO( Provider<Session> sessionProvider ) {
        this.sessionProvider = sessionProvider;
    }

    @Inject 
    public synchronized void setIt(PersistenceService service) {
        if ( ! isPersistenceServiceStarted ) {
            service.start();
            isPersistenceServiceStarted = true;
        }
        } 
}

In what situation (if any) would I expect the SessionHolder to be null?

Original issue reported on code.google.com by forum.na...@gmail.com on 30 Mar 2008 at 8:58

Attachments:

GoogleCodeExporter commented 9 years ago
Hello,

your problem is that setIt() is never getting run (try debugging this). This is 
because Guice does not scan up the 
class hierarchy for @Inject methods. Instead, use the "eager-singleton" 
initializer pattern shown in the 
documentation in http://www.wideplay.com

Dhanji.

Original comment by dha...@gmail.com on 31 Mar 2008 at 8:07

GoogleCodeExporter commented 9 years ago

Original comment by dha...@gmail.com on 31 Mar 2008 at 8:08

GoogleCodeExporter commented 9 years ago
setIt() actually is getting called when I instantiate the DAO implementations 
via my
Guice Injector. I happen to only have 2 DAO classes that extend 
GenericHibernateDAO.
When the first is instantiated, it runs fine. I can see setIt being called. 
After the
2nd is instantiated, setIt() is called again but as per the logic above, I do 
not
start the persistence service again. However, at this point, all of the 2nd DAO
methods fail with the NPE mentioned above

Original comment by forum.na...@gmail.com on 1 Apr 2008 at 12:56