@ElementCollection + nested @Embeddable -> @Enumerated ignored

Description

None

Activity

Show:

Michał Sobkiewicz June 21, 2023 at 3:01 PM

Confirmed, thanks for good news!

Christian Beikov June 21, 2023 at 11:53 AM

This is not reproducible anymore with Hibernate 6.2.5.Final. Also see

Michał Sobkiewicz November 19, 2022 at 8:38 AM
Edited

I've tried this once more with updated dependencies. I'm sad to say that 6.1.5.Final is still affected by this bug. Hibernate ignores @Enumerated(EnumType.STRING) if @Access(AccessType.FIELD) is not present at nested @Embeddable.

It’s been after almost a year and a half now. At least some confirmation would be nice. Thanks in advance.

Michał Sobkiewicz June 28, 2021 at 5:49 PM

As I recall, ORM works properly if nesting is “less complex”. For instance:
- @ElementCollection List<IdentityDocument> is fine (collection of plain embeddables),
- @Embedded IdentityDocumentUsage is also fine (embedded twice, but 1-1 instead of 1-n).

Please let me know if I can help you somehow.

Michał Sobkiewicz June 28, 2021 at 5:39 PM
Edited

Please review, clone and run mvn test to replicate.

Something similar to the following should be logged:

However, when you remove @Access(AccessType.FIELD) at IdentityDocument, @Enumerated at type is going to be ignored.

As you can see, type is being mapped to integer instead of varchar.

I believe that this may be a bug in org.hibernate.cfg.AnnotationBinder. For some reason it tries to read annotations at getType() method instead of type field (at the same time accessType is org.hibernate.cfg.AccessType.DEFAULT instead of org.hibernate.cfg.AccessType.FIELD). As this annotations list is empty, Hibernate uses ordinal based mapping which would be default without @Enumerated(STRING).

Fixed

Details

Assignee

Reporter

Sprint

Fix versions

Affects versions

Priority

Created June 28, 2021 at 5:15 PM
Updated June 30, 2023 at 11:45 AM
Resolved June 21, 2023 at 4:32 PM