8000 Registering a `PersistenceTypeResolver` is ignored if `executeTypeHandlerRegistration` is called first · Issue #292 · eclipse-store/store · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
BBA4

Registering a PersistenceTypeResolver is ignored if executeTypeHandlerRegistration is called first #292

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
magneticflux- opened this issue Sep 29, 2024 · 1 comment

Comments

@magneticflux-
Copy link

Environment Details

  • EclipseStore Version: 1.4.0
  • JDK version: 21
  • OS: Linux (NixOS)
  • Used frameworks: Spring

Describe the bug

I'm developing some custom persistence for Kotlin classes that are normally not handled because they are synthetic (ones that are less ambiguous than Java anonymous classes). To do that, I create a custom PersistenceTypeResolver wrapping the default and register it using PersistenceFoundation::setTypeResolver. Unfortunately, this didn't work right away because of some confusing behavior.

I was using the Spring Boot integration, and it defaults to org.eclipse.store.register-jdk17-handlers=true, which means before I even received the EmbeddedStorageFoundation<?> from the EmbeddedStorageFoundationFactory it had a type handler silently registered. It took a few minutes to track down why typeResolver wasn't updating, but once I traced the source of the default PersistenceTypeResolver it led directly to that initial call to executeTypeHandlerRegistration.

I worked around the issue by disabling automatic registration of handlers (JDK 8 and 17), doing my custom initialization with setTypeResolver, and then manually calling .onConnectionFoundation(BinaryHandlersJDK{8,17}::registerJDK{8,17}TypeHandlers) along with my other custom type handlers.

To Reproduce

Register a custom type resolver after registering a custom type handler and log what type resolver is used - it will be the default type resolver instead of the custom one.

Expected behavior

Type handlers shouldn't just make a copy of whatever the current type resolver was when they were created. Off the top of my head, they could either look that up whenever needed by referencing the foundation, or have some kind of "baking" step where they copy over everything they need when the EmbeddedStorageFoundation<?> is done being set up. I suppose it depends on the performance implications if the results aren't cached.

This seems similar to #204 and #203 (comment)

@hg-ms
Copy link
Contributor
hg-ms commented Oct 2, 2024

The described behavior is caused by the current foundation implementations. As soon as a component requires a second component for its initialization that second one is created using the default implementation if not set before. If such a second component is replaced by a custom one, it won’t be used by already initialized components.
Unfortunately this behavior can have some annoying side effects. Especially with Spring Boot.
As this behavior is caused by the current foundation architecture, we are not going to change that soon.

As workaround disabling the automatic initialization and doing a custom initialization that takes care of the required order is the best option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0