DATACMNS-649 - Added test case to show implementation class' transaction configuration gets picked up for method overrides as fallback.

This commit is contained in:
Oliver Gierke
2015-02-24 12:06:06 +01:00
parent 7ed684b0ab
commit d1b21f4239
2 changed files with 24 additions and 7 deletions

View File

@@ -64,7 +64,15 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
* Redeclaration of {@link CrudRepository#findOne(java.io.Serializable)} to change transaction configuration.
*/
@Transactional
public User findOne(Integer primaryKey);
User findOne(Integer primaryKey);
/**
* Redeclaration of {@link CrudRepository#delete(java.io.Serializable)}. to make sure the transaction configuration of
* the original method is considered if the redeclaration does not carry a {@link Transactional} annotation.
*
* @see DATACMNS-649
*/
void delete(Integer id);
/**
* Retrieve users by their email address. The finder {@literal User.findByEmailAddress} is declared as annotation at

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2011 the original author or authors.
* Copyright 2008-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,11 +39,8 @@ import org.springframework.transaction.TransactionStatus;
@ContextConfiguration({ "classpath:config/namespace-autoconfig-context.xml", "classpath:tx-manager.xml" })
public class TransactionalRepositoryTests extends AbstractJUnit4SpringContextTests {
@Autowired
UserRepository repository;
@Autowired
DelegatingTransactionManager transactionManager;
@Autowired UserRepository repository;
@Autowired DelegatingTransactionManager transactionManager;
@Before
public void setUp() {
@@ -85,6 +82,18 @@ public class TransactionalRepositoryTests extends AbstractJUnit4SpringContextTes
assertFalse(transactionManager.getDefinition().isReadOnly());
}
/**
* @see DATACMNS-649
*/
@Test
public void invokeRedeclaredDeleteMethodWithoutTransactionDeclaration() throws Exception {
User user = repository.saveAndFlush(new User("foo", "bar", "foo@bar.de"));
repository.delete(user.getId());
assertFalse(transactionManager.getDefinition().isReadOnly());
}
public static class DelegatingTransactionManager implements PlatformTransactionManager {
private PlatformTransactionManager txManager;