NHibernate "database" schema confusion [. \ Hibernate-mapping \ @schema]

I use NHibernate mainly against the MSSQL database, where I used MSSQL schemas for different tables.

In NH mapping (HBM) files, I specified the schema for each table in the mapping as follows:

<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   auto-import="true"
                   schema="xyz">                 <!-- schema specified -->
  <class name="Customer">
    <id name="Id">
      <generator class="native" />
    </id>
    <property name="Name" />
  </class>
</hibernate-mapping>

For my unit testing, I experimented with SQLite, however my mappings now do not work, since NH reports that the database "xyz" was not found.

I understand that there is a difference in the interpretation of schema , so what is NH interpretation / implementation and what is the best approach when using a schema?

BTW: An Internet search using keywords such as “nhibernate database schema” didn’t match anything.

+3
3

"" , : "CATALOG.SCHEMA.TABLE": , "information_schema" ISO-SQL?). Hibernate ( NHibernate) , , default_catalog default_schema .

unit test ( Hypersonic) Hibernate SessionFactory: , , HSQL- IdentifierGenerators, , , .

, . Oracle , ; PostgreSQL, ; SQL Server, "dbo".

+6

NHibernate.Mapping.Table GetQualifiedName(NHibernate.Dialect.Dialect dialect), :

public string GetQualifiedName(NHibernate.Dialect.Dialect dialect)
{
    string quotedName = this.GetQuotedName(dialect);
    return ((this.schema == null) ? 
        quotedName : 
        (this.GetQuotedSchemaName(dialect) + '.' + quotedName));
}

, SQLite , ( ).

+1

You can specify the schema (if you need one) in the configuration file using the property default_schema. You can use multiple configuration files or modify the one you are using, one for production and one for testing.

Perhaps you can just ignore the schema settings and use different credentials.

+1
source

Source: https://habr.com/ru/post/1708729/


All Articles