Gestor de entidades de hibernación GWT-P + JPA

I'm trying to use Hibernate's EntityManager in a GWT-P application.

Unfortunately it looks like I cannot use the proposed PersistFilter

public class MyModule extends ServletModule {
  protected void configureServlets() {
    install(new JpaPersistModule("myJpaUnit"));  // like we saw earlier.
    filter("/*").through(PersistFilter.class);
  }
}

causa ClassCastException:

org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider

So I'm trying other approach (unless you have a suggestion for this one).

I must be pretty close to get a first service to work, but the injected EntityManager es siempre null

public class ImageMetaDataService {
    @Inject EntityManager em;
    @Transactional
    public void createNewImageMetaData(ImageMetaDataImpl imd) {
        em.persist(imd);
    }
}

I suspect I make a mistake in setup. Is there a difference in using install(new JpaPersistModule("name")); (en DispatchServletModule) versus adding JpaPersistModule Me gusta esto:

public class MyGuiceServletContextListener extends GuiceServletContextListener {
    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new ServerModule(), new DispatchServletModule(), new JpaPersistModule("name"));
    }
}

And finally my most important question: How would I start JPA. Documentation suggest a class like this:

public class MyInitializer { 
        @Inject MyInitializer(PersistService service) {
                service.start(); 
                 // At this point JPA is started and ready.
        } 
}

But I don't see how to do that (in GWT-P).

preguntado el 08 de noviembre de 11 a las 13:11

¿Has encontrado una solución? -

1 Respuestas

Regarding your "most important question", that MyGuiceServletContextListener is a ServletContextListener. over-ride the default implementation of

public void contextInitialized(ServletContextEvent servletContextEvent) {
        persistService = injector.getInstance(PersistService.class);
        persistService.start();
}

then your going to want to also implement contextDestroyed to stop the serive:

@Override
public void contextDestroyed(ServletContextEvent contextEvent) {
    if (persistService != null) {
        persistService.stop();
    }
}

In both of these methods, the injector variable is cached locally before it is returned from the getInjector() method.

contestado el 14 de mayo de 12 a las 17:05

Is the injector actually created by the time the context is initialized? - pschuegr

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.