We have an entity defined in a 3rd party package which defines a sequence generator for its id:
We should not change this class (as it is someone else's) so would wish to be able to override this via an orm file:
However the intended override in the orm file is ignored in the case of a generic generator. Inspecting the class JPAOverriddenAnnotationReader suggests that generic generator has been omitted (for example there are mappings set up in the annotationToXml map for SequenceGenerator and TableGenerator but not for GenericGenerator).
I will submit a test case shortly in the form of a Maven/Eclipse project containing a small JPA app demonstrating this. I also have a proposed fix by extending JPAOverriddenAnnotationReader to include generic generators in a similar fashion to how it currently deals with sequence or table generators. Once I am satisfied that this fix addresses the issue I intend to submit a pull request.
I have attached a test case in the form of an Eclipse/Maven project containing a JUnit test case. The entity class EntityWithGenId uses a sequence generator to generate its myId field (so values 1, 2, 3 ...). The orm file for that entity type tries to override the choice of generator that is specified in the annotation with a generic generator which generates an id based upon a string field on the object (silly example I know but it serves to illustrate the issue.)
The test case creates three of these and checks their id is what is expected if generated by the custom generic generator - which it is not, the ids remain as generated by the sequence generator. So, the override in the XML has not been picked up. With a small amount of additions to the JPAOverridenAnnotationReader it is possible to make this work - so I will produce a proposed fix and submit it for consideration as a pull request.
I see there is a problem here - I had missed the fact that generic generators are a Hibernate rather than a JPA concept and hence can't be included in a mapping ORM document if it is to comply with the orm.xsd. So I can either carry on with my fix on the pragmatic basis that it works but any mappings documents which use it won't comply with the JPA schema, or I could give up. Any thoughts anyone?