2012-12-31 44 views
1

我有一个bean,它在构造函数中访问JPA,例如从数据库中预加载缓存。play.exceptions.JPAException:JPA上下文未初始化

在应用程序启动时,我收到

Caused by: java.lang.IllegalStateException: Unable to create Guice injector 

应用程序启动

1) Error injecting constructor, play.exceptions.JPAException: The JPA context is not initialized. 
JPA Entity Manager automatically start when one or more classes annotated with the @javax.persistence.Entity annotation are found in the application. 

这个问题的根本原因,即吉斯是创造我的bean实例,发挥inits JPA失败之前吉斯注入的原因实体经理。剩下的JPA代码工作正常,如果我在bean的构造函数中注释JPA调用,它也可以正常工作。

配置我的豆子,使用如下代码片段:

public class MainGuiceModule extends AbstractModule { 
    @Override 
    protected void configure() { 
      bind(UserManager.class).to(UserManagerImpl.class).in(Singleton.class); 
       ... 
     } 
} 

的问题是,如何从构造函数使用播放访问JPA!和Guice?

回答

2

终于让我找到怎样的方式来避免这种例外,我必须包装injecor的创作与

play.Play.plugin(JPAPlugin.class).startTx(true); 

play.Play.plugin(JPAPlugin.class).closeTx(false); 

我会接受的答案更优雅的解决方案

相关问题