Skip to content

Marking entity as new using EntityInformation fails #2046

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
JonasProgrammer opened this issue Apr 25, 2025 · 0 comments
Open

Marking entity as new using EntityInformation fails #2046

JonasProgrammer opened this issue Apr 25, 2025 · 0 comments
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@JonasProgrammer
Copy link

JonasProgrammer commented Apr 25, 2025

Hi,
I currently have the problem of marking an entity as new, even though it has a non-null UUID as id. The basic idea is to use a null-object pattern with the special case of a new UUID(0, 0), rather handling Nullability.

Reading around #1587 either Persistable or providing a custom EntityInformation is suggested. For my use-case, Persistable has the downside of clashing with data class definitions in Kotlin having a id member, which clashes with the getId function (though it does not satisfy the interface somehow...).

EDIT: Forgot to mention I am using Spring Boot 3.4.4, which, as far as I can tell, matches the version of spring-data-relation, spring-data-r2dbc, and the common shared stuff.

So I tried to go down the road of supplementing a R2dbcRepositoryFactoryBean with getEntityInformation overridden to return a delegate of the super call, overriding isNew to my liking. The factory bean does get instantiated once per repository, but the getEntityInformation method never gets called (both verified using breakpoints in the debugger). Returning a delegating subclass of R2dbcRepositoryFactory with a similar approach to its getEntityInformation method yielded the same result.

So when one would want to go down the rabbit hole of providing a custom implementation for EntityInformation, how does one actually do this properly?

Kind regards

--
Aside from that, as a meta question: We have the null/0-default hardcoded logic, Persistable as an intrusive way of doing things, and (presumably) EntityInformation working very low-level. Is there a specific reason, why something in between is unfeasable? I saw a EntityIsNewStrategy with implementations for the hardcoded null/0, and the persistable logic.
One could give the user the ability to supply something akin as beans. And while I get not going through a chain as in web filters, for example, for performance reasons, one could choose the best matching implementation from an ordered list, where each participant could implement a boolean supports(Class<?> domainType) or something.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2025
@mp911de mp911de self-assigned this Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants