Use of CDI to create built-in generators upon metadata creation, leading to errors if CDI is not yet initialized
Description
caused by
is fixed by
Activity
Steve Ebersole January 3, 2022 at 2:23 PM
That’s fine. There is a “solution” for 5.6, so that’s the important part. I had assigned this for 5.6 because I worked on that PR that we decided to not apply. Just forgot to remove it here I guess

Yoann Rodière January 3, 2022 at 8:05 AM
I may be misremembering, but I don’t think I fixed this in 5.x. I just used a workaround (overriding the identifier generator factory) in my experimental branch of WildFly, same as what is currently done in Quarkus. And from what I can see, the problematic code didn’t change in 5.6, so nobody else woked on this, either.
I’ll remove 5.6 from the “fix versions”.
Steve Ebersole December 19, 2021 at 1:29 PM
Technically, this was already fixed by Yoann for 5.x and myself for 6.x before the last releases of each. Did not make it into the release notes for either it would seem.
Anyway, as far as I know this is done on both
Steve Ebersole December 18, 2021 at 12:44 PMEdited
Currently we just ignore CDI if either delayed
or extended
is used.
Ultimately we will allow use of managed generators in those cases as well, but that requires a lot of internal (as well as some SPI) changes. See
Details
Assignee
Steve EbersoleSteve EbersoleReporter
Yoann RodièreYoann RodièreComponents
Fix versions
Priority
Major
Details
Details
Assignee
Reporter

See https://hibernate.zulipchat.com/#narrow/stream/132094-hibernate-orm-dev/topic/CDI.20for.20identifier.20generators.20in.20WildFly
I was surprised to see that this very simple mapping causes an error with ORM 5.6.1 in WildFly (probably 5.5 as well, though I didn't check):
@Entity @Indexed public class Book { @Id @GeneratedValue Long id; @Field String title; }
Apparently we added support for ID Generators defined as CDI beans at some point, but in WildFly, CDI is not yet available when we boot Hibernate ORM and create ID generators. I guess that's an acceptable limitation for custom ID generators, but the problem is we try to use CDI even for "standard" generators such as the mapping above.
The problematic code:
https://github.com/hibernate/hibernate-orm/blob/83975eaddf7f04680f12a1059eb737730da5ce6b/hibernate-core/src/main/java/org/hibernate/id/factory/internal/DefaultIdentifierGeneratorFactory.java#L121-L142
When we end up there,
strategy
is"org.hibernate.id.enhanced.SequenceStyleGenerator"
and isn't contained ingeneratorStrategyToClassNameMap
, so we try to create a bean. Which I guess we shouldn't?