Search code examples
hibernatedependenciesguiceguice-servletguice-persist

Dependency problems upgrading Guice with Warp-Persist


We have an application that uses Guice 1.0 with warp-servlet and warp-persist, and we'd like to upgrade to Guice 2 or 3. However, we're hitting a web of dependencies that is making it complicated.

Does anyone know of a simple way (as close as possible to drop-in replacement) to either make warp-persist work with newer Guice, or make Guice-persist work with straight Hibernate?

  • Warp-persist requires warp-servlet
  • Warp-servlet and warp-persist only support Guice 1.0
  • Guice-persist appears to be a replacement for warp-persist, but it only supports JPA, whereas we use Hibernate directly (with a significant legacy of criteria-based code that makes porting to JPA non-trivial).
  • Guice-persist also claims to have a way of supporting non-JPA data access, but there doesn't appear to be any documentation of this.
  • Warp-persist doesn't seem to support Hibernate 4, so we can't upgrade Hibernate either.

Solution

  • you can access the hibernate session from a JPA entity manager. This allows you to use migrate away from warp.

    @Singleton
    public class SessionProvider implements Provider<Session> {
    
        /** The entity manger to retrieve the session from. */
        @Inject
        private Provider<EntityManager> entityManagerProvider;
    
        /**
        * @return the Hibernate session, being the delegate of the entity manager provided by the injected entity manager provider.
        */
        @Override
        public Session get() {
            final Session session = (Session) entityManagerProvider.get().getDelegate();
            return session;
        }
    }
    

    All you need to do is configure Hibernate to be you JPA implementation. Also I would recommend to use onami persist. Guice persist seems to be abandoned.