-
Notifications
You must be signed in to change notification settings - Fork 28
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
Repository to (optionally) return managed JPA entities (JPA integration) #264
Comments
Hello @lprimak, how are you? I updated the spec to return the EntityManager using conventional methods. Also, we are discussing about the entity lifecycle on this issue: Do you think it would help? |
Hi, Otavio!
If my assumption is correct, I would want the ability to pick which This would also permit the return of managed entities from finder methods, using the correct entity manager. Hopefully this makes things more clear. Thank you! |
The spec still needs to be updated to explicitly say so, but the intent is to return entities that are not managed, consistent with a stateless entity manager.
|
Understood, with the implication that it would limit Data's usefulness when adding to current JPA-based codebases. I think in that case, spec needs to be updated to say so explicitly, with a caveat that the feature may be added in the future to integrate more tightly with JPA Does spec mention how a persistence unit is picked currently, it there are multiple ones? I might have missed it or it's not there. |
The spec has |
Ah, that's what I was missing, thanks Nathan! |
We can solve this issue by specifying that a resource accessor method may be annotated with a CDI qualifier annotation, for example: @Repository
interface JpaRepo {
@DocumentDatabase
EntityManager entityManager()
...
} WDYT? |
Sorry, @njr-11, I had missed this comment. That indeed is reasonable as a way to disambiguate datastores and persistence units by name. On the other hand, it doesn't let me use CDI qualifiers, as in my previous comment, or as in the issue description. |
Alternatively, I guess you could used CDI method injection, for example: @Repository
interface JpaRepo {
@Inject void init(@DocumentDatabase EntityManager entityManager);
...
} But I actually hate method injection and I guess I think this is significantly worse. (If, admittedly, more standard.) |
I personally like the CDI qualifier solution, but either one will work for me :) |
Perfect! |
Description
As far as I understand it, the repository finder methods return POJOs and not managed entities. In order to integrate with existing JPA codebases, it would be very useful if managed entities were returned.
As a:
All that would be needed is a reference to EntityManager. I propose to infer EntityManager from CDI,
similar to what's implemented here: https://docs.flowlogix.com/#section-daohelper
where
NonDefaultEM
is a custom@Qualifier
annotation that points to a producer method that injects the appropriate EM.Default would be no-qualifier injection, which would work in most cases.
The text was updated successfully, but these errors were encountered: