-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Request for EntityCallback Support in Quarkus MongoDB Panache #44066
Comments
@FroMage @loicmathieu @xstefank I have opened this issue regarding to #43989 discussion. |
I'd rather follow the same semantics as JPA lifecycle listeners, using annotations: https://jakarta.ee/specifications/persistence/3.2/jakarta-persistence-spec-3.2#lifecycle-callback-methods I could not find any similar lifecyle listener support in Jakarta Data, though perhaps @gavinking can contradict me. |
Yes you can. I mentioned this with the intention of giving developers more freedom to separate any logic from the entity class, keeping it clean and focused. It also allows custom logic to reside in a separate class for better organization. |
In our implementation of Jakarta Data, you can hook into the, My proposal for There is not yet any firm plan to add Jakarta Data-specific events. |
Of course, if you want something higher-level and better-integrated with CDI, then what you are looking for is integration with the CDI event bus. (Much netter than inventing a whole new eventing infrastructure as proposed above.) It should be quite straightforward to write a JPA I'm sure I've displayed an example implementation of such an |
There is now. See my proposal here: jakartaee/data#876 |
That was fast 😅 |
/cc @loicmathieu (mongodb) |
@loicmathieu @FroMage |
I think if this would be added to Jakarta Data, it would be a good idea to implement something similar. But for the moment, Panache is not tied to Jakarta Data, and I'm not sure we want to wait for it to be available, but we can still implement the same and then move to the new event classes when they exist. And of course, we would need that to be implemented for both Hibernate with Panache and MongoDB with Panache. |
Description
Summary: I would like to propose the addition of EntityCallback support in Quarkus, similar to the functionality provided by Spring. Specifically, I am looking for the following callbacks:
AfterConvertCallback: Invoked after an entity is converted from its database representation to its domain representation.
BeforeConvertCallback: Triggered before an entity is converted to its database representation.
AfterSaveCallback: Occurs after an entity is saved to the database.
BeforeSaveCallback: Invoked before an entity is saved to the database.
Use Cases: Implementing these callbacks would allow developers to execute custom logic at different stages of the entity lifecycle, enhancing flexibility and maintainability.
Implementation ideas
I’m adding a rough implementation idea here for adding EntityCallback support in Quarkus MongoDB Panache. Please feel free to update or suggest any better approaches!
Implementation Ideas for EntityCallback Support in Quarkus MongoDB Panache
1. Define Callback Interfaces:
Create interfaces for each callback (e.g., BeforeConvertCallback, AfterConvertCallback, BeforeSaveCallback, AfterSaveCallback).
Each interface can have a method that accepts the entity type as a parameter.
2. Implement a Callback Registry:
Create a registry to hold all registered callbacks. This could be done using a Map<Class<?>, List> to group callbacks by entity type.
3. Enhance the Panache Repository:
Enhance the PanacheMongoRepository / ReactivePanacheMongoRepository (MongoOperations / ReactiveMongoOperations)
4. Register Callbacks:
Allow users to register callbacks using CDI (Contexts and Dependency Injection) annotations, such as @singleton or @ApplicationScoped.
5. Testing
Implement component test cases to verify that the callbacks are invoked correctly during the entity lifecycle.
The text was updated successfully, but these errors were encountered: