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.

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;
    public void createNewImageMetaData(ImageMetaDataImpl 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 {
    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) {
                 // 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);

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

public void contextDestroyed(ServletContextEvent contextEvent) {
    if (persistService != null) {

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.