In our app, these are the layers used:
在我们的应用程序中,这些是使用的层:
Rest Service Endpoint Layer --> Business Layer --> DAO --> ORM
Now, each layer translates its exceptions appropriately and sends them to the next layer. For example, DAO Layer
creates a DaoException
and throws to Business Layer
, Bussiness Layer
translates this to BusinessException
which throws it to RestService Layer
where it is handled by a cxf mapper (okay, not really in RestServiceLayer).
现在,每个层都适当地转换其异常并将它们发送到下一层。例如,DAO Layer创建一个DaoException并抛出到Business Layer,Bussiness Layer将其转换为BusinessException,将其抛出到RestService Layer,由Cxf映射器处理它(好吧,不是在RestServiceLayer中)。
We have put @Transactional
on the methods of Business Layer
. So, if an exception happens at commit, the exception
will be fist seen only in the Rest Service Endpoint Layer
. Now, I will have to check for transaction commit related exceptions(eg. RollBackException etc.
) in the topmost layer (Rest Service Endpoint Layer
), which would kind of defeat the purpose of each layer translating the exceptions for the next layer.
我们已将@Transactional放在Business Layer的方法上。因此,如果在提交时发生异常,则只能在Rest Service Endpoint Layer中看到异常。现在,我将不得不检查最顶层(Rest服务端点层)中的事务提交相关异常(例如RollBackException等),这会破坏每层转换下一层异常的目的。
What would be a good way of dealing with this situation? Should I not translate exceptions at all and handle all of them only on the topmost layer?
处理这种情况的好方法是什么?我是否应该根本不翻译异常并仅在最顶层处理所有异常?
1 个解决方案
#1
0
Write an annotation-driven AOP point-cut on exception thrown and have that translate if you really want to translate and apply the annotation to your business layer. But I would also recommend against translating - what are you gaining by having the translation?
在抛出异常时编写注释驱动的AOP切入点,如果您真的想要翻译并将注释应用于业务层,请进行翻译。但我也建议不要翻译 - 你通过翻译获得了什么?
#1
0
Write an annotation-driven AOP point-cut on exception thrown and have that translate if you really want to translate and apply the annotation to your business layer. But I would also recommend against translating - what are you gaining by having the translation?
在抛出异常时编写注释驱动的AOP切入点,如果您真的想要翻译并将注释应用于业务层,请进行翻译。但我也建议不要翻译 - 你通过翻译获得了什么?