Skip to content

Allow configuring the order of built-in EntityCallbacks #4914

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

Open
rfelgent opened this issue Mar 8, 2025 · 6 comments · May be fixed by #4968
Open

Allow configuring the order of built-in EntityCallbacks #4914

rfelgent opened this issue Mar 8, 2025 · 6 comments · May be fixed by #4968
Assignees
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement

Comments

@rfelgent
Copy link
Contributor

rfelgent commented Mar 8, 2025

Hi @mp911de ,

the @Order of the built-in EntityCallbacks (at the time of writing AuditingEntityCallback and ValidatingEntityCallback) is not distinctive, both have the same configuration

        @Override
	public int getOrder() {
		return 100;
	}

Furthermore, I would like to make the value referencable by exposing them as public constant, e.g.:

public static final int ORDER = xxx;

This change allows a clean code regarding ordering of the buit-in and app provided EntityCallbacks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 8, 2025
@mp911de
Copy link
Member

mp911de commented Mar 10, 2025

Auditing and validation should be orthogonal aspects that ideally should not affect each other. We're using Order to avoid falling into the Ordered.LOWEST_PRECEDENCE basket.

This change allows a clean code regarding ordering of the buit-in and app provided EntityCallbacks.

I am not quite sure how this would really help as the value is a static one. I could imagine on the other side to introduce setOrder(…) to configure ordering. That is a common pattern in Spring Framework (e.g. UrlBasedViewResolver, ProxyProcessorSupport) providing quite some flexibility to change ordering.

@mp911de mp911de self-assigned this Mar 10, 2025
@rfelgent
Copy link
Contributor Author

Hi @mp911de ,

I am not sure, If I could make clear the concerns regarding similar @Order values.

How do you know the order of entity callback if they all have the same order ? I think, there is already some kind of dependencies between callbacks.
Example: The AuditingCallback might manipulate fields annotated with @NotNull (e.g. modifiedBy). Therefore, I would like to have a guaranteed order, that the ValidatingEntityCallback gets triggered as last.

@mp911de
Copy link
Member

mp911de commented Mar 10, 2025

Isn't using @NotNull on a @LastModifiedBy like writing a unit test to verify the framework is working correctly? That being said, I'm not sure what type of issue you're trying to solve.

Apart from that, introducing setOrder(…) on our callback implementations, enabling your application to customize the order, is totally fine with us.

@rfelgent
Copy link
Contributor Author

I will Provide a merge request

@mp911de mp911de added status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 11, 2025
@mp911de mp911de changed the title make the @Order of built-in EntityCallbacks distinctive and usable Allow configuring the order of built-in EntityCallbacks Mar 11, 2025
@yangchef1
Copy link

yangchef1 commented May 10, 2025

Hi @mp911de , I noticed that this issue has been open for some time.
If no one is actively working on it, I’d be happy to pick it up and submit a PR.
If someone else is already working on it, please feel free to let me know!

@mp911de
Copy link
Member

mp911de commented May 12, 2025

Feel free to submit a pull request @yangchef1

yangchef1 added a commit to yangchef1/spring-data-mongodb that referenced this issue May 13, 2025
…tyCallback.

Added corresponding test cases for this functionality.

Closes spring-projects#4914
Signed-off-by: yangchef1 <[email protected]>
yangchef1 added a commit to yangchef1/spring-data-mongodb that referenced this issue May 13, 2025
…tyCallback.

Added corresponding test cases for this functionality.

Closes spring-projects#4914
Signed-off-by: yangchef1 <[email protected]>
yangchef1 added a commit to yangchef1/spring-data-mongodb that referenced this issue May 14, 2025
…tyCallback.

Added corresponding test cases for this functionality.

Closes spring-projects#4914
Signed-off-by: yangchef1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with type: enhancement A general enhancement
Projects
None yet
4 participants