3

再生用にカスタム 404.html ページ (app/views/errors 内) を提供しています! 1.2.5

404 の提供中に DB に接続したいのですが、そうすると次のようになります。

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 が典型的な再生リクエスト以外のリクエストライフサイクルに入る理由はありますか?

4

1 に答える 1

1

try/finally 内で JPAPlugin メソッドの startTx および closeTx を使用できます。

JPAPlugin.startTx(false);
try {
    // your code
} finally {
    JPAPlugin.closeTx();
}
于 2013-01-08T09:09:38.500 に答える