spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

Transaction marked as rollback only when initialising application when working with transaction manager [DATAJPA-1686]

Open spring-projects-issues opened this issue 5 years ago • 6 comments

mirackle-spb opened DATAJPA-1686 and commented

Looks like DATAJPA-617  is not completely resolved. My app doing some data work while context initialisation is in progress. Inserting default data to database. When it initialising it depends on JpaReposiotory. When spring tries to initialise Repository spring-data-jpa make check for existence of named queries.

Within NamedQuery.javaa when lookupEm.createNamedQuery is called. Later Hibernate in AbstractSharedSessionContract query is not found and exceprion is fired. Hibernate ExceptionConverterImpl fire markForRollbackOnly.

Spring-data catches this exception but it is not matter at this point. Transaction is already marked.

Problem reproduced in 100% of cases when JTA transaction manager is in use


Affects: 2.2.4 (Moore SR4)

spring-projects-issues avatar Feb 24 '20 09:02 spring-projects-issues

mirackle-spb commented

Possible solution: We can create new transaction within hasNamedQuery method for lookup purpose only

spring-projects-issues avatar Feb 24 '20 09:02 spring-projects-issues

Jens Schauder commented

Please provide a reproducer, i.e. a small complete project demonstrating this issue preferable in the form of a failing test

spring-projects-issues avatar Mar 09 '20 10:03 spring-projects-issues

Sławomir Luty commented

Jens Schauder Hi, I think I have such example. Should I attach it as zip(how) or publish repository somewhere ?

spring-projects-issues avatar Nov 01 '20 00:11 spring-projects-issues

Jens Schauder commented

slawomir.luty Both is possible, but I prefer a Github repository

spring-projects-issues avatar Nov 02 '20 08:11 spring-projects-issues

Sławomir Luty commented

Take a look at this one, please:

https://github.com/slo/jpa-example/tree/error_reproduced

I prepaired it to use external jboss eap 7.3, but I think it is possible to also run with wildfly (maybe even embedded). If any help is needed regarding this repository, don't hesitate to ask. Sorry for the mess, but I only wanted to reprodce this error - if any simplification is needed - I can do it

spring-projects-issues avatar Nov 02 '20 20:11 spring-projects-issues

I have a similar problem. My spring configuration is annotated with "@EnableJpaRepositories( bootstrapMode = BootstrapMode.LAZY...". When I use a repository for the first time inside a transaction and it includes query methods like "findByMycolumn", my transaction will be marked as rollbackonly for the same reason.

dbarciela avatar Jan 20 '22 15:01 dbarciela