0

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.
ThrawnCA
  • 1,051
  • 1
  • 10
  • 23

1 Answers1

1

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.

sclassen
  • 138
  • 3
  • This nearly works! We're just hitting problems with the SessionPerRequestFilter, which is complaining that UnitOfWork must be 'REQUEST'. We're setting that, but presumably it isn't being set in the appropriate place now that we're calling PersistenceService.usingJpa() instead of usingHibernate() – ThrawnCA Jun 30 '15 at 01:35
  • Update: all we had to do was change from the Hibernate SessionPerRequestFilter to the JPA one. It's now working :) – ThrawnCA Jun 30 '15 at 01:44