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

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

问题描述

我使用的是 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"类只定义了两个成员:私有 int id;

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

和私人长时间戳;

因此,我知道当我扩展那个类时,那些将是我应该期望的列名.然而,令人困惑"的问题是:为什么当我没有扩展默认值时,列是不同的(分别是 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天全站免登陆