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

Reactive Repositories are not supported by JPA. Need spring-webflux + spring-data-jpa combination get working [DATACMNS-1413] #1847

Closed
spring-projects-issues opened this issue Oct 26, 2018 · 4 comments
Assignees
Labels
in: repository status: declined type: task

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Oct 26, 2018

Maksim Kostromin opened DATACMNS-1413 and commented

Hello spring team!

We are already using in production spring-boot 2.0.4.RELEASE (webflux rest api + spring-data-jpa) and today during versions upgrade I found that next release versions (not 2.0.5.RELEASE, nor 2.0.6.RELEASE) doesn't support that combination anymore:

2018-10-26 19:09:37.936 ERROR 40994 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.dao.InvalidDataAccessApiUsageException: Reactive Repositories are not supported by JPA. Offending repository is daggerok.fileitems.domain.FileItemRepository!
        at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.useRepositoryConfiguration(RepositoryConfigurationExtensionSupport.java:310) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE]
        at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.getRepositoryConfigurations(RepositoryConfigurationExtensionSupport.java:103) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE]
        at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:126) ~[spring-data-commons-2.0.10.RELEASE.jar:2.0.10.RELEASE]
        at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:60) ~[spring-boot-autoconfigure-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.lambda$loadBeanDefinitionsFromRegistrars$1(ConfigurationClassBeanDefinitionReader.java:358) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[na:1.8.0_192]
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:357) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:145) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:328) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
        at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:61) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]

I understand purpose of error message and also know that we can get benefit from non-blocking stack by using it fully from data-layer to REST API, but... Is it possible somehow for us continue using our current stack with spring-webflux + spring-data-jpa on latest 2.0.6.RELEASE without migration to r2dbc, which is not stable yet (at least, as far as I know)?

What I need is maybe you can suggest me to exclude some dependencies or auto-configurations which were added since 2.0.5.RELEASE?

Thanks in advice!


Affects: 2.0.11 (Kay SR11)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 30, 2018

Mark Paluch commented

Care to attach your FileItemRepository code to this ticket? Spring Data is not preventing you from using JPA in WebFlux. Spring Data prevents usage of reactive types in JPA repositories

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 30, 2018

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 31, 2018

Mark Paluch commented

Thanks a lot. Spring Data considers your repository a reactive one as it contains method signatures that use reactive types (Mono, Flux). Reactive types are used in default methods only, yet we're quite strict on preventing potential inappropriate usage.

Please also note, that reactive types do not imply the execution context (i.e. which thread is used) and context switching (using schedulers) can easily break JPA's transaction context. Also, Stream usage requires an outer transaction. When using reactive types, these type of boundaries aren't obvious anymore so we opted for a stricter validation.

Closing this ticket with works as designed

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Oct 31, 2018

Maksim Kostromin commented

So please, correct me if I'm wrong:

  1. Should I use separate service-wrapper around JPA repo instead of using Mono/Flux with default methods?
  2. Should I avoid using Publisher.subscribeOn(Schedulers.elastic()) due to Transactional context?

@spring-projects-issues spring-projects-issues added status: declined in: repository type: task labels Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository status: declined type: task
Projects
None yet
Development

No branches or pull requests

2 participants