English 中文(简体)
检测PlayFramework 中数据库持久性失败
原标题:Detecting database persistence failure in PlayFramework

我正在与Playframeforform 1. 2x公司建立一个应用程序

我得在进行CROUD业务时 检测数据库操作是否成功

这是我到现在为止拥有的

public static void create(Args..) {
        Model m = new Model(Args..);
        m.save();
        if(m.id == null) {
        // Render failure Response
        }else {
        // Render Success Response
        }
}

public static void read(long id) {
        Model m = Model.findById(id);
        if(m == null ) {
            // Render failure Response
        }else{
            // Render Success Response
        }
}

我不知道对 UPDATE DELETE 必须做些什么。

上述方法并不十分优雅。 是否有更好的解决办法,比如例外?

我试图关闭数据库服务器, 从而给我一个 Pististenceexpendion 。 是否有类似的例外?

最佳回答

是的, 如果您有数据库连接问题, 您将会有一些由 ORM 丢弃的例外。 持久性例外是 JPA 例外的根源, 所以如果 ORM 检测到例外, 您就有这种例外 。

对我来说,抓获意外的例外不是办法。 如果你有这样的技术问题,你的数据库会让你们重回困境,没有东西可以保存。

只要抓住例外, 对用户意味着某些东西, 让其他用户上去, 然后播放会显示通用的 500页, 在此情况下 Name

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签