Why does overriding change column names

时光毁灭记忆、已成空白 提交于 2020-01-04 04:00:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!