2013-01-07 35 views
2

我們提供自定義404.html頁面(在應用程序/視圖/錯誤)玩! 1.2.5有沒有辦法在使用EntityManager!框架1.2.x 404頁面?

在服務404,我們想連接到數據庫,但這樣做的時候,我們得到:

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. 
at play.db.jpa.JPA.get(JPA.java:22) 
at play.db.jpa.JPA.em(JPA.java:51) 
at play.db.jpa.JPQL.em(JPQL.java:18) 
at play.db.jpa.JPQL.find(JPQL.java:46) 
... 
at controllers.Security.check(Security.java:146) 
at play.utils.Java.invokeStaticOrParent(Java.java:162) 
at play.utils.Java.invokeChildOrStatic(Java.java:184) 
at controllers.Secure$Security.invoke(Secure.java:203) 
... 
at play.server.PlayHandler.serve404(PlayHandler.java:681) 

我應該去像https://stackoverflow.com/a/12242994/1444089的解決方案 - 這樣定義自己的控制器的處理程序,而不是隻模板?

也許有一些配置選項,但找不到一個。

最後但並非最不重要的 - 爲什麼會發生這種情況,404有一個原因是爲什麼404會在一些其他請求生命週期中比一個典型的播放請求?

回答

1

你可以使用一個try /終於

JPAPlugin.startTx(false); 
try { 
    // your code 
} finally { 
    JPAPlugin.closeTx(); 
} 
內JPAPlugin方法startTx和closeTx
相關問題