-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Custom user types considered entities on Hibernate >= 5.4.22 #2421
Comments
@odrotbohm Could you take a look at this? |
Is there a chance we get a slightly simpler (read: Maven / Java sample project)? Using a very niche infrastructure arrangement makes working (as in execute, debug, tweak) with the project much harder than it'd need to be. I'd like to avoid to put anything JPA / Hibernate specific into the metamodel inspection on SD RESTs side. If at all, this needs to go somewhere in the I'll continue by investigating how much insight we can get into all of this by inspecting the |
Looks like we can't expect too much help from the Hibernate team here. After internal discussion, we should be able to tighten the guards to only merge entities (in the Spring Data sense) that expose an identifier. That discussion also again brought to light that the notion of “entity” in the context of Spring Data mapping is more like “mapped type” (as in: type, we need to inspect and unfold to persist) and we're going to investigate to adapt the internal APIs to better reflect that. Never mind the demo project, actually. I got it running in IDEA. |
Looks like we need to move this to Spring Data JPA. The least invasive way of fixing this is in mitigating Hibernates change right in front of the JPA |
…rsions > 5.4.21. Hibernate 5.4.22 started including types managed by custom user types in the embeddables exposed via JPA's Metamodel API. This causes those to be considered types to explicitly map (read: unfold) in Spring Data REST. We now exposed a cleaned up view on this via a tweak in JpaPersistentPropertyImpl (ultimately in JpaMetamodel) looking for @embeddable annotation on types allegedly considered embeddable by Hibernate. Fixes #2421.
…rsions > 5.4.21. Hibernate 5.4.22 started including types managed by custom user types in the embeddables exposed via JPA's Metamodel API. This causes those to be considered types to explicitly map (read: unfold) in Spring Data REST. We now exposed a cleaned up view on this via a tweak in JpaPersistentPropertyImpl (ultimately in JpaMetamodel) looking for @embeddable annotation on types allegedly considered embeddable by Hibernate. Fixes #2421.
…rsions > 5.4.21. Hibernate 5.4.22 started including types managed by custom user types in the embeddables exposed via JPA's Metamodel API. This causes those to be considered types to explicitly map (read: unfold) in Spring Data REST. We now exposed a cleaned up view on this via a tweak in JpaPersistentPropertyImpl (ultimately in JpaMetamodel) looking for @embeddable annotation on types allegedly considered embeddable by Hibernate. Fixes #2421.
Fixes in place in all branches ( |
Thank you for the quick fix! I tried with I assume the fix for the custom user type being seen as embeddable fixed the whole thing. The other issue, of JsonNodes not mapping to writeable properties might still exist, but doesn't affect us with the Money deserialization now (because the money object is mapped to a writeable property, only the "amount" wasn't). |
After the serialization issue was fixed (thank you!), I tried again to upgrade Spring Boot.
This time, we're having problems with the Deserialization on PATCH request of Java Money.
There are two problems:
@Transient annotation won't deserialize fields on MongoRepository PATCH requests [DATAREST-1524] spring-data-rest#1881
DATAREST-1383 causes top level properties with @JsonSetter to be missed. [DATAREST-1573] spring-data-rest#1911
Custom Serializers cannot apply patch method [DATAREST-1566] spring-data-rest#1928
A check was introduced, that if a
JsonNode
doesn't map to a writable property, theJsonNode
is removed and ignored.That's a problem whenever the JSON doesn't map directly to a property in the entity, but is converted or parsed in any other way: transient fields with setters,
@JsonSetter
, or custom serializers.On the original issue there was also the comment
but I don't think the fix has been been revisited.
CompositeUserType
like the JadiraPersistentMoneyAmountAndCurrency
is now registered in the Hibernate metamodel as an embeddable and theDomainObjectReader
check withisEntity
whether a type is managed by Hibernate (IMO,isEntity
is a bit of a misnomer here, it not only checks for entities, but for any managed type: entities, mapped superclasses and embeddables). So, now aMoney
is treated as an entity with nested properties, instead of passing it as a value object to theMonetaryAmountDeserializer
. MaybeisEntity
could return falseCompositeUserTypes
? (I'm not sure how to do that without some Hibernate-specific code and it probably needs to have no knowledge of Hibernate here.)I have setup a demo to reproduce the issues (with some hacky workarounds).
The text was updated successfully, but these errors were encountered: