-
Notifications
You must be signed in to change notification settings - Fork 30
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
[Use Case]: Annotations for use with Jakarta Persistence #470
Comments
See #143. |
Please see #477. |
Alright, so I guess I need to rewind a bit here and fully explain why I'm now proposing to do something we said we wouldn't do. CRUD vs JPASo, right from the start I've been pointing out the deep, fundamental differences in semantics between the semantics of JPA, and the semantics which were contemplated for simple repository lifecycle methods. Let's start by considering a simple
OK, a bit of a mismatch, but perhaps neither of those differences is a showstopper. Unfortunately it gets worse from there. First, JPA literally has no Nor does JPA have a CRUD repositories for JPA entitiesOK, so does that mean that we have to give up, and throw away the concept of a repository with Absolutely not! Hibernate can easily implement such a repository using its So I understand that @njr-11 was holding out hope that perhaps one can "emulate" the semantics of But it's not the way JPA is intended to be used, and I would say it just doesn't really work out:
So I would never implement a repository this way. Why is this even a problem?The problem is that the current spec has explicit language in sections 6.4 and sections 7.1.1 which deal with JPA and say stuff about how a JPA-backed repository should work. In my opinion, these sections of the spec should not be defining how a Hibernate-backed repository might work. And that's exactly what this language was doing:
The most natural way to read this is that it appears to be prescribing that a JPA-backed repository be implemented in exactly the way I just say I would "never implement a repository". Worse, there's what I understand to be an actual TCK test for this functionality in What to do about itFrom my point of view, there's two possible fixes:
There's really not much work involved in option 2, and I really don't think anyone needs to be freaking out about it. I've already done the required work on the annotations and on the spec. And I can fix the TCK in a jiffy. But of course if ya'll prefer to do option 1, then I for one am totally fine with that. Folks, I do understand and appreciate the desire to get something out, but it's much more important to make sure that what we get out is actually correct and not just wrong. |
There are other ways to emulate stateless delete and update operations that are currently possible in Jakarta Persistence, such as issuing a JPQL DELETE or UPDATE. In some cases, such as if the user chooses an update method signature that returns the entity and it has autogenerated values, approaches like these may be suboptimal in advance of Jakarta Persistence adding the stateless entity manager, but I do think it should be possible to emulate stateless in advance of it. In the case of Hibernate, you already have stateless. I do think it is important to have stateless as the default behavior of Jakarta Data. One of the primary aims of Jakarta Data is to have a simple and intuitive programming model for data access. While the stateful behavior of Jakarta Persistence is quite useful and can be more efficient, it is a level of complexity that basic users should not need to deal with/learn/think about unless they want it. The default behavior of Jakarta Data should be stateless, which is what we have been aiming for and written the spec/API for in version 1.0. It certainly makes sense for more advanced users/Jakarta Persistence users to be able to opt in to stateful, which has been in the plans for post version 1.0. |
I agree. That's what I've been saying for approximately forever. So then the path seems clear: I will send a pull request that deletes sections 6.4 and 7.1.1 of the specification. And we will address JPA integration in a future release of Jakarta Data. |
As a ...
I need to be able to ...
write a portable repository backed by JPA.
Which enables me to ...
be more independent of the Jakarta Data provider.
Additional information
So I know we all said we didn't want to do this in this release. But with all the machinery we've defined, it's now frankly trivial.
We would add:
@Persist
,@Merge
,@Refresh
,@Lock
,@Remove
, and@Detach
, and@JPQL
and I guess also@SQL
in new package
jakarta.data.orm
.The semantics of the lifecycle annotations are completely defined by the JPA spec. Because they're specific to JPA/ORM, we have zero work to do, it's just a
@see
annotation that points to the corresponding operation ofEntityManager
.It's similarly clear what
@JPQL
does. On the other hand, perhaps we don't need it and all we need to do is give people explicit permission to put their JPQL in the@Query
annotation. (I can see arguments both ways.)Finally, if I recall correctly, at some stage someone (Otavio I guess) had proposed a built-in
JpaRepository
. I don't argue that we need it, but if you all still want it, it's completely trivial to define in terms of the annotations listed above.So why is this now so easy when previously it was "hard". Well, before, we were trying to shoehorn JPA into the existing
@Save
annotation or whatever. But now that our model of lifecycle annotations is extensible, it's no longer hard.Dunno. I guess I feel like it's now become a bit hard to justify not doing it.
Reactions?
The text was updated successfully, but these errors were encountered: