-
Notifications
You must be signed in to change notification settings - Fork 31
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
complete (portable) support for Jakarta Persistence #477
Conversation
==== | ||
This release of Jakarta Data does not standardize lifecycle annotations or query annotations for use with Jakarta Data providers backed by Jakarta Persistence. | ||
==== | ||
Alternatively, a Jakarta Data provider might support repositories whose associated entities are annotated `jakarta.persistence.Entity` and mapped according to the Jakarta Persistence specification, but whose lifecycle methods are annotated with the Jakarta Data annotations `@Insert`, `@Update`, and `@Delete`. Such a repository is "stateless", in the sense that it does not maintain a persistence context which outlives the invocation of a single repository method. The lifecycle operations of this kind of repository adhere to the usual semantics defined by this specification for the annotations listed. In particular, these operations never cascade to related entities. Such a repository is typically not permitted a resource accessor method of type `jakarta.persistence.EntityManager`, since `EntityManager` is designed for use with stateful persistence contexts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@njr-11 as promised, this reintroduces the support for stateless sessions.
I like this specialization! Question: Can we have a module specific to ORM? Instead of putting it at the core, we have a module specific to ORM/JPA. This way, the scope of the core will still be cross-databased, and a new module/jar will be included in this specialization. classDiagram
Core <|-- ORM
|
Ah, yeah, sure, we could. Not sure it's really necessary since—for now at least—it's just six annotations with no dependencies on anything. But I'm not against doing that.... |
Also, @otaviojava, you need to tell me if you want an |
So here's a wrinkle: if you want such an interface, we would probably need to pick up a dependency to Jakarta Persistence, which would argue in favor of a separate module. Here's I guess what it would look like, approximately: /**
* <p>A built-in repository supertype for repositories backed by a Jakarta Persistence
* {@code EntityManager}.</p>
*
* @param <T> the type of the primary entity class of the repository.
* @param <K> the type of the Id attribute of the primary entity.
*/
public interface OrmRepository<T, K> extends DataRepository<T, K> {
@Find
T find(K id);
@Find
T find(K id, FindOption... options);
@Persist
void persist(T entity);
@Persist
void persistAll(Iterable<T> entities);
@Remove
void remove(T entity);
@Merge
T merge(T entity);
@Detach
void detach(T entity);
@Refresh
void refresh(T entity);
@Refresh
void refresh(T entity, RefreshOption... options);
@Lock
void lock(T entity, LockModeType lockModeType);
@Lock
void lock(T entity, LockModeType lockModeType, LockOption... options);
EntityManager entityManager();
} |
Note that I don't personally find that interface very compelling. It's just sort of a worse |
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package jakarta.data.orm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be called jakarta.data.jpa
, since ORM is too generic and broad a term and some of these annotations whilst they look useful are JPA/Hibernate specific
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy with "orm" either, but as I have the impression that the Jakarta spec aren't using the name "JPA" anymore. The JPA spec itself doesn't use the term, it's "Jakarta Persistence" everywhere.
(I think this is stupid, FTR, and I'm fine with "jpa".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the Jakarta Persistence uses the jakarta.persistence
, how about:
jakarta.data.persistence
At the end, it is a specialization of Jakarta Data to Jakarta Persistence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
jakarta.data.persistence
Fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JPA is more common for developers, we are familiar with jpa, cdi, etc in Jakarta EE world.
Yeap, once ORM is a specialization of DataRepository. |
Yes, this was the main reason for proposing the module. Thus, you can go deep into Jakarta's Persistence to create a better user experience without impacting the code. |
Yeah, sure, makes sense. I have no objection to that. Just don't expect me to do Maven things 'cos I'm clueless :-) |
I can use your branch as a base to propose this new module. |
Perfect. |
Closing this since #480 was merged instead. |
This proposes an implementation of #470, along with spec language properly specifying how Jakarta Data supports JPA.