Skip to content

Hibernate-48 investigation #105

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

NathanQingyangXu
Copy link
Contributor

We need to straighten out some doubts for Hibernate-48. This DRAFT PR will contain various commits to showcase the validation results.

throw new FeatureNotSupportedException(format("%s is not supported", DynamicInsert.class.getSimpleName()));
}
metadata.visitRegisteredComponents(component -> {
if (component.getStructName() != null && component.getProperties().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for empty @Embeddables that are not @Struct? Hibernate ORM also omits storing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the above only applies to STRUCT (STRUCT must have name so telling whether the struct name is present suffices).
If we want to enlarge the forbidding to any @Embeddable, I think we simply drop the struct name checking above as below:

if (component.getProperties().isEmpty()) {
    ... ...
}

var holder = new StructHolder();
holder.id = 1;
holder.emptyStruct = new EmptyStruct();
session.persist(holder);
Copy link
Member

@vbabanin vbabanin Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the produced MQL result in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{"insert": "books", "documents": [{"author": {"firstName": null, "lastName": null}, "_id": 1}]}

From my understanding, @DynamicInsert only covers an entity's root level fields. If the field is special type like STRUCT or array, it goes out of its scope how they are gonna to be persisted, as long as the field per se is non-null.

In our product, we use STRUCT to implement embedded doc and seeminly the same behavour should apply to the embeded doc; but this is our wishful thinking, for STRUCT is mainly used for SQL's User Defined Type. In traditional Hibernate design, all fields value should be provided to STRUCT (there is no analogy of @DynamicInsert for STRUCT; again, @DynamicInsert is only meant for entity class).

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

Successfully merging this pull request may close these issues.

3 participants