问题
I was using the default implementation of the rev listener and as expected the columns in my REVINFO table were: revtstmp and rev.
However, when I overrode the default - all I did was:
... MyRevisionEntity extends DefaultRevisionEntity
those column names were changed to "timestamp" and "id".
Anyone know why?
Using envers 4.1.5_Final...
** EDIT ** As no one has yet answered, I am adding more information.
The Adam Warski authored "DefaultRevisionEntity" class defines only two members: private int id;
and private long timestamp;
Thus, I understand that when I extend that class, those will be the column names that I should expect. However, the "baffling" question is: why was it that when I did NOT extend the default, the columns were different (rev and revtstmp respectively) and also what the documentation said?
Thanks for any help!
回答1:
The short answer is because when you don't extend, Envers uses a default configuration that has those column names hardcoded, e.g. they don't originate from the entity class's metadata. When you extend the DefaultRevisionEntity
, Envers defaults to using standard ORM naming strategies.
More technically speaking, RevisionInfoConfiguration
is the culprit here.
As a part of the bootstrap of Envers, the #configure()
method of this class is called and it searches the defined entities for a custom revision entity implementation. If an implementation is detected, Envers basically maps the class like any other entity.
But if no custom implementation is detected, generateDefaultRevisionInfoXmlMapping
is called which will automatically build the appropriate XML structure, which uses hard-coded column names for the @RevisionNumber
and @RevisionTimestamp
annotated fields; ergo you get the columns named REV
and REVTSTMP
.
I've registered a JIRA issue HHH-11325 to address the improvement.
来源:https://stackoverflow.com/questions/12736811/why-does-overriding-change-column-names