Fix: Remove @Embeddable from classes already annotated with @Entity #6513
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request addresses an issue with classes in the HAPI FHIR JPA module that were annotated with both
@Entity
and@Embeddable
. Such dual annotations are now explicitly disallowed by Hibernate as part of stricter validation introduced in recent versions (e.g., Hibernate 6.6.0 and later). This change ensures compliance with both JPA specifications and Hibernate’s new validation rules, resolving startup errors caused by conflicting annotations.Background
Hibernate Stricter Validation
Starting with Hibernate 6.6.0, stricter validation rules were introduced to prevent classes from being annotated as both
@Entity
and@Embeddable
. These two annotations serve distinct and incompatible purposes:@Entity
: Indicates that a class is a standalone entity with its own database table.@Embeddable
: Indicates that a class is not a standalone entity but instead is embedded within another entity’s table.The presence of both annotations on a single class is logically inconsistent, leading to ambiguous behavior and runtime errors. Hibernate now throws an
AnnotationException
for such configurations.Problem
The dual annotations caused the following error at application startup when using Hibernate 6.6.2:
Solution
This pull request removes the
@Embeddable
annotation from all affected classes that were also annotated with@Entity
. By doing so:The modifications ensure that all classes function correctly as standalone entities with proper mappings to their respective database tables.
References