升级数据库版本是否会潜在地改变异常调用堆栈?

发布于 2025-01-21 01:47:42 字数 1065 浏览 4 评论 0原文

在我的代码中,我一直坚持一排数据,并且在DB级别施加了约束违规时,有一个捕获块来丢弃(自定义)错误。我必须如何到达那里有点混乱,但它起作用了。

catch (RollbackException ex){
      if(ex.getCause() instanceof PersistenceException) {
        PersistenceException pe = (PersistenceException) ex.getCause();
        if (pe.getCause() instanceof ConstraintViolationException) {
          ex.printStackTrace();
          throw new ApolloDBSaveException("ConstraintViolationException while saving Itinerary, could be concurrency issue", ex);
        }
      }
    } 

现在出于神秘的原因,似乎被抛出的错误不再是rollbackexception的实例,因此我只需要在PersistenceException级别上抓住它即可。

catch (PersistenceException ex) {
      if (ex.getCause() instanceof ConstraintViolationException) {
        ex.printStackTrace();
        throw new ApolloDBSaveException("ConstraintViolationException while saving Itinerary, could be concurrency issue", ex);
      }
    } 

我如此困惑的是,我没有对JPA实现层(Hibernate 5.4.2. -final)或对我放在桌子上的约束进行任何更改。我唯一能想到的是,在某个时候,我们将Postgres从版本10升级到版本11,但是从应用程序的角度来看,开关是看不见的。这会改变错误吗?我很难在网上找到任何东西来支持最接近的工作理论。

In my code, I was persisting a row of data and had a catch block to throw a (custom) error when a constraint violation was thrown at the DB level. It was a bit messy how I had to get there but it worked.

catch (RollbackException ex){
      if(ex.getCause() instanceof PersistenceException) {
        PersistenceException pe = (PersistenceException) ex.getCause();
        if (pe.getCause() instanceof ConstraintViolationException) {
          ex.printStackTrace();
          throw new ApolloDBSaveException("ConstraintViolationException while saving Itinerary, could be concurrency issue", ex);
        }
      }
    } 

Now for mysterious reasons, it seems the error getting thrown is no longer an instance of RollbackException so I had to just catch it at the PersistenceException level.

catch (PersistenceException ex) {
      if (ex.getCause() instanceof ConstraintViolationException) {
        ex.printStackTrace();
        throw new ApolloDBSaveException("ConstraintViolationException while saving Itinerary, could be concurrency issue", ex);
      }
    } 

What has me so perplexed is I haven't made any changes to the JPA Implementation Layer ( Hibernate 5.4.2.Final) or anything specific about the constraint I put on the table. The only thing I can think of is at some point we upgrade postgres from version 10 to version 11 but from an app standpoint that switch was invisible. Would that change the error getting thrown? I'm having trouble finding anything online to support the closest working theory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文