Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Transactional customizations not applied correctly on redeclared methods [DATACMNS-715] #1178

Closed
spring-projects-issues opened this issue Jun 10, 2015 · 7 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jun 10, 2015

Avishay opened DATACMNS-715 and commented

public interface RepositoryExample extends JpaRepository<User, String>{
	
        // This Query's timeout just works 
	@Query("FROM User")
	@Transactional(timeout = 10,propagation = Propagation.REQUIRED)
	public List<User> findAll2();
	
        //The query below - timeout doesn't work , the @Transactional timeout is not being applied
        // Although in the documentation it shows it suppose to work exactly as below 
        @Override	
	@Transactional(timeout = 10,propagation = Propagation.REQUIRED)
	public List<User> findAll();
}

Recommendation: In order to debug it put breakpoint in EntityManagerFactoryUtils.applyTransactionTimeout


Affects: 1.8.5 (Dijkstra SR5), 1.9.2 (Evans SR2), 1.10 GA (Fowler), 1.11 M1 (Gosling)

Issue Links:

  • SPR-13109 Provide means to opt out of default annotation based transaction management by bean
    ("depends on")

  • DATAJPA-755 Overriding @Transactional on repository method not working
    ("is duplicated by")

  • DATACMNS-778 Backport fix for @javax.transaction.Transactional support

  • DATACMNS-732 JTA 1.2's @Transactional not being applied to query methods

Backported to: 1.10.1 (Fowler SR1), 1.9.3 (Evans SR3), 1.8.6 (Dijkstra SR6)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 10, 2015

Oliver Drotbohm commented

Do you have a test case showing that this really doesn't get applied? I debuged your example into TransactionalRepositoryProxyPostProcessor.AbstractFallbackTransactionAttributeSource.computeTransactionAttribute(…) and can see this code path being followed:

if (specificMethod != method) {
	// Fallback is to look at the original method.
	txAtt = findTransactionAttribute(method);
	if (txAtt != null) {
		return txAtt;
	}
}
…

method is the method declared in the interface, specificMethod is the method of the implementation. As you can see the redeclared method gets inspected and the transaction attributes annotated to it get selected

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 10, 2015

Avishay commented

In order to debug it put breakpoint in EntityManagerFactoryUtils.applyTransactionTimeout and observe the :
query.setHint("javax.persistence.query.timeout", timeoutValue);
is not set for the the findAll() but it does set for findAll2()

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 10, 2015

Oliver Drotbohm commented

Please don't mess with the ticket settings. What is the environment you're using this in? I can reproduce the failure with a default Boot setup. Are you using Boot, too by any chance?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 10, 2015

Avishay commented

i'm using Boot as well (1.2.3) and by looking in the effective pom i see spring-data-jpa is 1.7.2

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 15, 2015

Oliver Drotbohm commented

Unfortunately this seems to be related to Spring Framework apply default transaction attribute discovery on top of the customized one we deploy anyway when using @EnableTransactionManagement which in turn gets activated automatically. This unfortunately breaks the redeclaration mechanism for CRUD methods. The workaround is to have a dedicated service layer with transaction annotations for those methods for now.

I've created SPR-13109 to keep track of the issue and we should see a fix for that quite soon in Spring 4.2 (Boot 1.3). Also, a back-port should make it into 4.1.7 so that we should be able to do service releases of Spring Data that refer to that fixed Spring version, too

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 15, 2015

Avishay commented

Thanks Oliver

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jun 17, 2015

Oliver Drotbohm commented

I've added support for the newly introduced TransactionProxy interface to opt out of additional transaction management in a reflective fashion so that it gets activated whenever a Spring Framework version shipping that interface is on the classpath.

We can probably optimize this for Fowler and Gosling once Spring 4.1.7 was released to avoid the reflective overhead and simplify the setup in general

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants