這是我在總結實施春季交易在不同的DAO不起作用嗎?
1)所有的DAO實現並採用的HibernateDAO支持/ @Transational註釋僅在服務層
2)使用主要使用MySQL/HibernateTransactionManager的
3)測試(使用String args [])方法(使用這種方法做事務工作嗎?)
事務沒有得到回滾,並且在數據庫中可以看到無效的entried。 我在這裏做錯了什麼?
詳細信息如下。
1)我已經配置使用@Transactional註釋在服務層事務處理:使用主
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/ibmdusermgmt" />
<property name="username" value="root" />
<property name="password" value="root" />
<property name="defaultAutoCommit" value="false"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingLocations"
value="classpath*:hibernate/*.hbm.xml" />
<property name="hibernateProperties">
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.query.substitutions">
true=1 false=0
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_outer_join">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
3)試驗:
@Transactional(readOnly=false, rollbackFor={DuplicateEmailException.class,DuplicateLoginIdException.class,IdentityException.class},propagation=Propagation.REQUIRES_NEW)
public void createUserProfile(UserProfile profile)
throws DuplicateEmailException, DuplicateLoginIdException,
IdentityException {
//Accessing DAO (implemented using HibernateDAOSupport)
identityDAO.createPrincipal(profile.getSecurityPrincipal());
try {
//Accessing DAO
userProfileDAO.createUserProfile(profile);
} catch (RuntimeException e) {
throw new IdentityException("UseProfile create Error", e);
}
}
2)我TRANSATION管理器配置/數據源被如下()方法如下:
public static void main(String[] args) {
ApplicationContext cnt=new ClassPathXmlApplicationContext("testAppContext.xml");
IUserProfileService upServ=(IUserProfileService)cnt.getBean("ibmdUserProfileService");
UserProfile up=UserManagementFactory.createProfile("testlogin");//
up.setAddress("address");
up.setCompany("company");
up.setTelephone("94963842");
up.getSecurityPrincipal().setEmail("[email protected]");
up.getSecurityPrincipal().setName("Full Name");
up.getSecurityPrincipal().setPassword("password");
up.getSecurityPrincipal().setSecretQuestion(new SecretQuestion("Question", "Answer"));
try {
upServ.createUserProfile(up);
} catch(Exception e){
e.printStackTrace();
}
由於GID, 我配置成使用 <類別名稱= 「org.springframework.transaction.support.AbstractPlatformTransactionManager」> <優先級值= 「INFO」/> 我不能看到像任何記錄的「創建的log4j新名稱的交易「。 ? – 2009-10-28 08:07:43
下一步是檢查您從上下文獲得的IUserProfileService實例是否是代理,並且該代理具有對TransactionInterceptor的引用,最好在調試器中執行此操作 – 2009-10-28 08:53:16