您是否使用一些 jsf 机制捕获异常?
如果是,那么 JSF 可能错过了那些 JPA 异常。您可以尝试通过 web.xml 捕获这些:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/error_redirect.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error_redirect.html</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error_redirect.html</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error_redirect.html</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error_redirect.html</location>
</error-page>
在“error_redirect.html”中,您可以重定向到“/faces/error.xhtml”或其他任何内容。
也许您也可以直接将这些条目指向“/error/”,但由于某种原因(我不记得)我使用了这个重定向 html :)