Allow to inject JPA repositories for different datasources
See original GitHub issueI have an application that needs to use the same JPA repository on different datasources. At first I tried to inject it with @PersistenceContext(name = "<datasource>")
like it works for a transaction manager but without success. I just found out that the @Repository
annotation can be used with a datasource name. But in my opinion that is the wrong place for this declaration. It requires to define multiple repository interfaces which have exactly the same structure. Possibly that could be solved with inheritance (haven’t tried) but it still contradicts the logical structure as that would be a declaration just for runtime purposes. It also makes it difficult to define repositories in libraries.
Wouldn’t it be possible to use the @PersistenceContext
annotation for repository injection too?
Expected Behaviour
Inject JPA repository variables for different (non-default) datasources.
Actual Behaviour
The datasource can only be controlled by @Repository
annotation, requiring to define multiple identical repository interfaces.
Environment Information
- Micronaut Version: 1.3.0.M2
- micronaut-data Version: 1.0.0.M5
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:17 (4 by maintainers)
I could flesh out my example code above.
I have a PR which should allow it https://github.com/micronaut-projects/micronaut-data/pull/1608