EJB2 CMP会话Bean默认事务属性及EJB2到EJB3迁移咨询
Great question—let's break this down clearly for your EJB2 to EJB3 migration.
First, here's your bean's definition from ejb-jar.xml for reference:
<session> <ejb-name>FileFacade</ejb-name> <home>file.FileFacadeHome</home> <remote>file.FileFacade</remote> <ejb-class>file.FileFacadeBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session>
Since this is a stateless session bean using container-managed transactions (noted by <transaction-type>Container</transaction-type>) and no transaction attributes are explicitly configured, the EJB2 specification dictates that the default transaction attribute is Required.
Interestingly, this matches EJB3's default transaction attribute! Here's what Required means in practice for your bean's methods:
- If an active transaction already exists when the method is called, the method runs within that transaction context.
- If no transaction is active, the container automatically creates a new transaction before executing the method.
This default is explicitly laid out in the EJB 2.1 spec: when no transaction attribute is specified for a container-managed transaction bean method, the container must assume the Required attribute.
For your migration, this is good news—this transaction behavior is consistent between EJB2 and EJB3, so you won’t need to adjust this bean’s transaction settings unless you want to override the default.
内容的提问来源于stack exchange,提问作者user771221

