I want to use transactionManager of spring. My spring configuration is here:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
depends-on="propertyPlaceholderConfigurer"
p:driverClassName="org.postgresql.Driver"
p:url="${db.url}"
p:username="${db.username}"
p:password="${db.password}"
destroy-method="close" />
<context:spring-configured />
<context:annotation-config />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
depends-on="flywayAutomaticMigrationBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.example" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.default_schema">restProj</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/example/db/hbm/user/AuthUser.hbm.xml</value>
<value>com/example/db/hbm/user/User.hbm.xml</value>
<value>com/example/db/hbm/user/Role.hbm.xml</value>
<value>com/example/db/hbm/user/Feature.hbm.xml</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="com.example.model" >
<context:include-filter type="regex" expression=".*\.dao\..*DAO"/>
<context:include-filter type="regex" expression=".*\.logic\..*Mgr"/>
</context:component-scan>
<context:component-scan base-package="com.example.commons" >
<context:include-filter type="regex" expression=".*\.dao\..*DAO"/>
<context:include-filter type="regex" expression=".*\.logic\..*Mgr"/>
</context:component-scan>
</beans>
And this is one of my Manager class:
import org.springframework.transaction.annotation.Transactional;
public class UserMgr extends BaseUserMgr {
@Transactional (rollbackFor = Exception.class)
public void checkTransaction(){
Feature feature = new Feature();
feature.setExtuid(UUID.randomUUID().toString());
feature.setName("boogh");
feature.setDescription("salam");
FeatureDAO.getInstance().save(feature);
}
}
When I run UserMgr.checkTransaction() Data doesn't save. Can anyone explane to me what is wrong?
__UPDATE___
This is my FeatureDao Save Method :
public java.lang.Long save(com.example.model.user.Feature feature)
throws org.hibernate.HibernateException {
return (java.lang.Long) super.save(feature);
}
and this is superclass Save method:
protected Serializable save(final Object obj) {
return save(obj, getSession());
}
and the getSession() method get session from spring sessionFactory.
And this is my FeatureDao getInstance() method:
public static com.model.user.dao.FeatureDAO getInstance() {
return com.example.core.spring.ApplicationContextUtil.getApplicationContext().getBean(com.example.model.user.dao.FeatureDAO.class);
}