Pergunta

I'm using Nhibernate Envers and I want Envers to save audit info on a separate database to keep things cleaner/more maintainable.

I'm using this fluent configuration:

var enversCfg = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration()

enversCfg.Audit(GetDomainEntities())
nhCfg.SetEnversProperty(ConfigurationKey.DefaultCatalog, "nhibernate_testAU")

but when I try to create the schema, I get a HibernateException (The specified schema name "nhibernate_testAU" either does not exist or you do not have permission to use it.)

for what it's worth, my backend is SQL Server 2005

Foi útil?

Solução

In addition to actually creating the database, I specified the schema to "dbo".

c.SetEnversProperty(ConfigurationKey.DefaultSchema, "dbo");  
c.SetEnversProperty(ConfigurationKey.DefaultCatalog, "MyCatalog_Audit");

Also, I have my own RevistionEntity class, so, I needed to add the catalog and schema to my hbm.

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MyAssembly" namespace="MyNamespace">
  <class name="MyRevisionEntity" table="REVINFO" catalog="MyCatalog_Audit" schema="dbo">
    <id name="Id" column="MyRevisionEntityId">
      <generator class="identity"/>
    </id>
    <property name="AuditDate"></property>
    <property name="UserName"></property>
    <!--modifiedEntityNames-->
    <set name="ModifiedEntityNames" table="REVCHANGES"  catalog="MyCatalog_Audit" schema="dbo">
      <key column="REV"/>
      <element column="ENTITYNAME" type="string"/>
    </set>
  </class>
</hibernate-mapping>

HTH

Chuck

Outras dicas

You need to manually create the catalog/database. AFAIK - NH's SchemaExport don't create database/catalog (or schemas) for you.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top