【发布时间】:2015-02-18 09:59:44
【问题描述】:
我们正在使用 JAX-RS 和 JPA。我们使用具有以下结构的方法(细节省略):
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ResultObject saveById( @PathParam("id") BigInteger id,
SomeObject someObject) {
entityManager = EMF.obtainEntityManager();
try {
.. start transaction
.. write all information to the database
.. commit transaction
.. return ResultObject
} catch ( Exception exception) {
.. rollback transaction
.. return ResultObject together with an appropriate error
} finally {
entityManager.close();
}
}
有没有一种“最好的”方法来避免重复捕获并最终在我们创建的每个 JAX-RS 方法上重复?使用过滤器? 我们的服务提供者只支持 Tomcat。没有 Glassfish 或其他容器。 感谢您的帮助。
【问题讨论】: