【问题标题】:Envers with NhibernateEnvers 与 Nhibernate
【发布时间】:2014-09-24 15:19:02
【问题描述】:

我正在使用 Envers 来审核我的一些数据库表。 审计工作正常,我可以在带有自定义前缀等的相应表中看到数据库中的数据。 我无法查询任何数据,因为我总是收到以下 QueryException:

无法解析属性:originalId of: NaturalPerson [select e__, r__ from NaturalPerson e__, ExtendedRevisionEntity r__ where e__.originalId.RevisionID.id = r__.id order by e__.originalId.RevisionID.id asc]

这是查询代码:

AuditReaderFactory.Get(session).CreateQuery().ForHistoryOf<NaturalPerson, ExtendedRevisionEntity>().Results();

NaturalPerson 的映射

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="Domain" namespace="Domain" xmlns="urn:nhibernate-mapping-2.2">
  <joined-subclass name="NaturalPerson"  schema="MySchema" table="NaturalPersons">
    <key column="PersonID" />
    <property name="Name" type="AnsiString"/>
  </joined-subclass>
</hibernate-mapping>

使用 fluent 进行 Envers 配置:

configuration.SetEnversProperty(ConfigurationKey.AuditTableSuffix, " ");
configuration.SetEnversProperty(ConfigurationKey.DefaultSchema, "aud"); 
configuration.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true);
configuration.SetEnversProperty(ConfigurationKey.RevisionFieldName, "RevisionID");
configuration.SetEnversProperty(ConfigurationKey.RevisionTypeFieldName, "RevisionTypeID");
enversConf.Audit<NaturalPerson>();

【问题讨论】:

  • 请为 NaturalPerson 进行映射和环境配置。
  • 我在答案中添加了该信息
  • “来自 NaturalPerson”的部分看起来有点可疑。您能查看生成的 sql 并验证它实际上是在尝试从审计表中读取吗?将 AuditTableSuffix 设置为空白/空格可能会出现问题。
  • 你是对的,后缀中的空格是问题,它可以用于写作但你不能查询,我认为这可能是envers查询API中的一个错误
  • 不知道有没有什么办法可以去掉envers后缀?我试过使用 string.Empty 但 Nhibernate 不会让我...

标签: nhibernate-envers


【解决方案1】:

如上面的 cmets 所述,问题在于 AuditTableSuffix 中的“唯一空格”。

代码中被审计的实体名称是 audittableprefix + "原始实体名称" + audittablesuffix

查询时,“空白”表示什么都没有(“select a from b a”变成“select a from b a”),会读取到错误的数据。

请在此处添加有关它的 JIRA 问题 https://nhibernate.jira.com/browse/NHE 最好有一个小的、孤立的失败测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多