2

私は、maven、gwt、gwt-platform、および guice-persist を使用して例を実行しようとしていました。

でも、困りました。

で例を実行しようとするとmvn gwt:run、次の例外が発生しました。

1) Error injecting constructor, javax.persistence.PersistenceException: [PersistenceUnit: exemplo] Unable to build EntityManagerFactory   at br.net.meditec.Exemplo.server.inject.AppInitializer.<init>(AppInitializer.java:9)   while locating br.net.meditec.Exemplo.server.inject.AppInitializer  1 error    at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)     at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)  at br.net.meditec.Exemplo.server.inject.GuiceServletConfig.getInjector(GuiceServletConfig.java:24)  at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:45)    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)   at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)     at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)     at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)   at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.Server.doStart(Server.java:222)    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)   at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)     at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)     at com.google.gwt.dev.DevMode.main(DevMode.java:311) Caused by: javax.persistence.PersistenceException: [PersistenceUnit: exemplo] Unable to build EntityManagerFactory     at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)    at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)     at br.net.meditec.Exemplo.server.inject.AppInitializer.<init>(AppInitializer.java:10)   at br.net.meditec.Exemplo.server.inject.AppInitializer$$FastClassByGuice$$96bdac91.newInstance(<generated>)     at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)   at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:60)    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)   at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)  at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)    at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)     at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)  at br.net.meditec.Exemplo.server.inject.GuiceServletConfig.getInjector(GuiceServletConfig.java:24)  at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:45)    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)   at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)     at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)     at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)   at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.Server.doStart(Server.java:222)    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)   at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)     at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)     at com.google.gwt.dev.DevMode.main(DevMode.java:311) Caused by: org.hibernate.HibernateException: Could not instantiate dialect class   at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:82)  at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)  at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:146)     at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)   at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)  at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)     at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2273)   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2269)   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1738)     at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:88)  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)    at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)     at br.net.meditec.Exemplo.server.inject.AppInitializer.<init>(AppInitializer.java:10)   at br.net.meditec.Exemplo.server.inject.AppInitializer$$FastClassByGuice$$96bdac91.newInstance(<generated>)     at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)   at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:60)    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)   at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)  at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)    at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)     at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)  at br.net.meditec.Exemplo.server.inject.GuiceServletConfig.getInjector(GuiceServletConfig.java:24)  at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:45)    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)   at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)     at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)     at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)   at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.Server.doStart(Server.java:222)    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)   at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)     at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)     at com.google.gwt.dev.DevMode.main(DevMode.java:311) Caused by: java.lang.ClassCastException: org.hibernate.dialect.PostgreSQLDialect cannot be cast to org.hibernate.dialect.Dialect   at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:73)  at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:64)  at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:146)     at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)   at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)  at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)     at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2273)   at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2269)   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1738)     at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:88)  at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)  at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)    at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)     at br.net.meditec.Exemplo.server.inject.AppInitializer.<init>(AppInitializer.java:10)   at br.net.meditec.Exemplo.server.inject.AppInitializer$$FastClassByGuice$$96bdac91.newInstance(<generated>)     at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)   at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:60)    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)   at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)  at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)    at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)     at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)  at br.net.meditec.Exemplo.server.inject.GuiceServletConfig.getInjector(GuiceServletConfig.java:24)  at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:45)    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)   at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)     at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)     at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)   at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)    at org.mortbay.jetty.Server.doStart(Server.java:222)    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)     at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)   at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)     at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)     at com.google.gwt.dev.DevMode.main(DevMode.java:311)

モジュールをEclipse経由で実行すると、別の例外が発生しました。

1) Error injecting constructor, javax.persistence.PersistenceException: No Persistence provider for EntityManager named exemplo
  at br.net.meditec.Exemplo.server.inject.AppInitializer.<init>(AppInitializer.java:9)
  while locating br.net.meditec.Exemplo.server.inject.AppInitializer

1 error
    at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1013)
    at br.net.meditec.Exemplo.server.inject.GuiceServletConfig.getInjector(GuiceServletConfig.java:24)
    at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:45)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
    at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:222)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
    at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
    at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
    at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
    at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
    at com.google.gwt.dev.DevMode.main(DevMode.java:311)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named exemplo
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    at com.google.inject.persist.jpa.JpaPersistService.start(JpaPersistService.java:94)
    at br.net.meditec.Exemplo.server.inject.AppInitializer.<init>(AppInitializer.java:10)
    at br.net.meditec.Exemplo.server.inject.AppInitializer$$FastClassByGuice$$96bdac91.newInstance(<generated>)
    at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
    at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:60)
    at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
    at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
    at com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1024)
    at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)
    ... 21 more

最初のエラーでは、PostgreSQLDialect が見つからないように見えます。2 番目のエラーでは、persistence.xml 自体が見つからないようです。

次の内容のクラスを作成しましたが、問題なく動作します。

public class DaoInjectionTest {
    public static void main(String[] args) {
        Injector injector = Guice.createInjector(new DaoModule(),
                new JpaPersistModule("exemplo"));
        injector.getInstance(AppInitializer.class);

        injector.getInstance(RacaDao.class).save(new Raca("cachorro pastor alemao"));
    }
}

だから、何が起こっているのか理解できません。誰かが助けることができますか?

それが役立つ場合、私のプロジェクトのコードは github にあります。

どうもありがとうございました。

4

0 に答える 0