如果方法没有持久化任何实体,那么使TransactionAttributeType.NOT_SUPPORTED变好

时间:2017-05-24 13:26:44

标签: java hibernate ejb ejb-3.1 jta

如果我有嵌套的bean方法,它只从数据库中获取数据。 (即GET API)。那么将所有bean方法标记为TransactionAttributeType.NOT_SUPPORTED是否有益?它有助于提高性能,因为JTA没有为此管理任何交易吗?

3 个答案:

答案 0 :(得分:4)

这正是使用NOT_SUPPORTED来提高性能的目的。事实如Oracle所述:

  

不支持的属性

     

如果客户端在事务中运行并调用   企业bean的方法,容器挂起客户端   调用方法之前的事务。方法之后   完成后,容器恢复客户的交易。

     

如果客户端未与事务关联,则容器会关联   在运行方法之前不要启动新事务。

     

对于不需要的方法,请使用NotSupported属性   交易。由于交易涉及开销,此属性   可以提高绩效

因此,它非常适合所有选择查找业务方法,其目的可能是填充屏幕上的数据表。

答案 1 :(得分:0)

NOT_SUPPORTED is useful if there is a processing that would cause an exception if invoked with transaction context. For example invoking stored procedure containing DDL code withing context of XA processing will cause an exception to occur. If changing stored procedure is not an option use NOT_SUPPORTED attribute as work around and suspend the transaction prior to invocation of method containing problematic stored procedure.

If transaction roll back is allowed in read only transaction use SUPPORTS , if transaction roll back is not allowed in read only transaction use NOT_SUPPORTED.

答案 2 :(得分:0)

本文说:“不,对只读查询使用NOT_SUPPORTED事务传播没有意义”。这是JPA专家Vlad Mihalcea写的。

Does TransactionAttributeType.NOT_SUPPORTED make sense for retrieving entities?