在這裏工作是我的服務方法:彈簧數據的JPA事務不會對服務
@Resource
private PersonRepository personRepository;
@Transactional
@Override
public Person create(PersonDTO created) {
LOGGER.debug("Creating a new person with information: " + created);
Person person = Person.getBuilder(created.getFirstName(), created.getLastName()).build();
personRepository.save(person);
foo();
return null;
}
public void foo() {
throw new RuntimeException();
}
正如你可以看見我拋出一個execption但persistancy發生非少。
這裏是我的數據源配置:
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/dbb"/>
<property name="username" value="root" />
<property name="password" value="pass" />
<property name="initialSize" value="10"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="15"/>
<property name="minIdle" value="10"/>
<property name="timeBetweenEvictionRunsMillis" value="10000"/>
<property name="minEvictableIdleTimeMillis" value="60000"/>
<property name="validationQuery" value="/* ping */ SELECT 1"/>
<property name="testOnBorrow" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="removeAbandoned" value="true"/>
<property name="removeAbandonedTimeout" value="300"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="punit"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="MYSQL"/>
<!-- <property name="databasePlatform" value="${hibernate.dialect}"/> -->
<property name="showSql" value="false"/>
<property name="generateDdl" value="false"/>
<!-- <property name="hibernate.connection.autocommit" value="false"/> -->
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.connection.autocommit" value="false" />
</map>
</property>
</bean>
任何想法,爲什麼?
謝謝!
重複實例(不支持事務)。注意你的配置'hibernate.connection'屬性在你注入一個'DataSource'時沒有做任何事情(但是混亂你的XML)。 –
我們使用INNODB,爲什麼您認爲我有重複的服務? – Urbanleg
你不會是第一個。如果您正在使用組件掃描,請確保您的ContextLoaderListener和DispatcherServlet不掃描相同的組件。還要確保服務在指定' '的上下文中加載。 –