Creating IdentifierGenerator instances - timing #4095
Replies: 2 comments 3 replies
-
I am not against it but I'm not sure about the consequences/problems if any of using reflection while building the |
Beta Was this translation helpful? Give feedback.
3 replies
-
Ok. In the absence of feedback I am going to have the transition from |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For a number of reasons I am working on making a single point of entry ("eye of the needle" as my mentor used to say) for the creation of IdentifierGenerators. Currently that creation can happen multiple times, sometimes even expecting failures and ignoring them expecting that a "later attempt" will succeed.
This causes me some difficulty working on HHH-14506, #3823 and friends.
The "expecting failures and ignoring them" happens during the building of
MetadataImpl
. Building the "boot model" reference is supposed to not attempt reflection at all. However, in existing code (5.x and earlier), the very last "phase" in building the Metadata is attempting to create these generators which often needs access to the Java type - is it UUID? Integer? String? ... This often fails and the code block in question uses try/catch and ignores any errors because the same exact thing (sans ignoring exceptions) happens in the SessionFactory constructor later on.My initial attempts to create the generators at a single point focused on the point in building Metadata, but this time with no try/catch/ignore handling. This worked great, but causes one test (
org.hibernate.orm.test.legacy.NonReflectiveBinderTest
) to fail because the test explicitly tries to make sure that no reflection happens building the Metadata (it tries to map non-existent classes).But interestingly enough, the existing try/catch/ignore approach expects all
Exportable
references (Sequence or Table) needed for the generator get registered during this try/catch/ignore processing. So it expects certain cases can (and do) fail and be caught and ignored. So in trying to keep the same semantic, I next tried to move to this creation phase to theSessionFactoryBuilder
handling which happens just before constructing the SessionFactory (duh). Again this works fine, but causes test failures. Specifically any test that expects the built Metadata to contain all Sequence and Table, including those for identifier) to be registered already, fail. They fail specifically because they only build a Metadata reference and expect the id-gen Exportables to be registeredIn my opinion this is a logical inconsistency and either one case or the other should "win". Personally I vote that we handle this id-gen creation as part of building the Metadata. I think that limiting reflection is perfect while building the actual mapping classes (
PersistentClass
, etc); but I think it is overkill once we get to the point of creating the actual Metadata instance in certain cases, and I think this id-gen creation is one of those.Beta Was this translation helpful? Give feedback.
All reactions