为什么覆盖会更改列名 [英] Why does overriding change column names

查看:118
本文介绍了为什么覆盖会更改列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是rev侦听器的默认实现,并且正如我期望的那样,我的REVINFO表中的列是:revtstmp和rev.

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

这些列名已更改为"timestamp"和"id".

those column names were changed to "timestamp" and "id".

有人知道为什么吗?

使用envers 4.1.5_Final ...

Using envers 4.1.5_Final...

**编辑** 由于尚未有人回答,我正在添加更多信息.

** EDIT ** As no one has yet answered, I am adding more information.

由亚当·沃斯基(Adam Warski)撰写的"DefaultRevisionEntity"类仅定义了两个成员: 私人整数ID;

The Adam Warski authored "DefaultRevisionEntity" class defines only two members: private int id;

和 私人长时间时间戳;

and private long timestamp;

因此,我知道在扩展该类时,这些将是我应该期望的列名称.但是,莫名其妙"的问题是:为什么当我不扩展默认值时,这些列是不同的(分别是rev和revtstmp),以及文档所说的呢?

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?

感谢您的帮助!

推荐答案

简短的答案是因为当您不进行扩展时,Envers使用默认配置,这些配置中的列名都经过了硬编码,例如它们不是源自实体类的元数据.扩展DefaultRevisionEntity时,Envers默认使用标准的ORM命名策略.

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.

从技术上讲,RevisionInfoConfiguration是这里的罪魁祸首.

More technically speaking, RevisionInfoConfiguration is the culprit here.

作为Envers引导程序的一部分,该类的#configure()方法被调用,并且它在定义的实体中搜索自定义修订版实体实现.如果检测到实现,则Envers基本上像其他任何实体一样映射该类.

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.

但是如果未检测到自定义实现,则调用generateDefaultRevisionInfoXmlMapping,它将自动构建适当的XML结构,该结构对@RevisionNumber@RevisionTimestamp带注释的字段使用硬编码的列名;因此,您会得到名为REVREVTSTMP的列.

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.

我已经注册了JIRA问题 HHH-11325 来解决此问题.

I've registered a JIRA issue HHH-11325 to address the improvement.

这篇关于为什么覆盖会更改列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆