标签: nhibernate-configuration

休眠配置文件中会话工厂名称属性的用途是什么

在 hibernate-cfg.xml 文件中,根据我的理解

hibernate-configuration 只能有一个 session-factory 和一个或零个安全标签

如果我们配置多个会话工厂,那么我们应该会得到错误

"The content of element type "hibernate-configuration" must match "(session-factory,security?)

所以有人告诉我

  1. hibernate.cfg.xml文件中session-factory标签中的name属性有什么用

    <session-factory name="">
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我们可以在什么场景下使用它?

java hibernate nhibernate-configuration

12
推荐指数
1
解决办法
1125
查看次数

web.config中的NHibernate配置 - 使用现有的连接字符串

我在我的web.config文件中成功设置了NHibernate配置.但是,我也使用ASP.NET Membership,它需要在connectionStrings元素中定义连接字符串.有没有办法让我的NHibernate配置使用这个值,所以我不需要两次定义连接字符串?

nhibernate nhibernate-configuration

10
推荐指数
1
解决办法
5353
查看次数

NHibernate需要Proxy Factory吗?

我在hibernate.cfg.xml中进行了这个配置:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=SSPI;</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

我刚刚创建了一个类库,并且我使用MbUnit创建了一个集成测试.它失败.报告的一部分(我认为足够了)在这里:

** NO TESTS WERE RUN (No tests found) **
TestCase 'M:IntegrationTests.RepositoryTests.ListAllPostsReturnsAListOfPost'
failed: The ProxyFactoryFactory was not configured.
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.
Run Code Online (Sandbox Code Playgroud)

我已经阅读了很多教程,并没有看到这个代理工厂配置.指定它真的有必要吗?如果是这样,我该怎么做?我是否要引用其他一些图书馆?

nhibernate nhibernate-configuration

9
推荐指数
1
解决办法
5277
查看次数

NHibernate:如何解决这个"方言"配置问题

遇到的问题

在运行时,我总是得到以下内容NHibernate.MappingException:

"Could not compile the mapping document: GI.InventoryManager.CYB.Mappings.Part.hbm.xml"
Run Code Online (Sandbox Code Playgroud)

是的,它的构建操作设置为Embedded Resource.InnerException说:

"Could not find the dialect in the configuration"
Run Code Online (Sandbox Code Playgroud)

需要的信息

这是我的配置文件名为hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">
        Server=(local);initial catalog=GI_IM_CYB;Integrated Security=SSPI
    </property>
    <property name="adonet.batch_size">10</property>
    <property name="show_sql">false</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="use_outer_join">true</property>
    <property name="command_timeout">60</property>
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,     NHibernate.ByteCode.Castle</property>
  </session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

实际上是Configuration_Templates文件夹中的复制粘贴,其中我只更改了以下信息:

Session Factory: "Removed the NHibernate.Test namespace and let the property …
Run Code Online (Sandbox Code Playgroud)

.net nhibernate nhibernate-configuration dialect

7
推荐指数
1
解决办法
2万
查看次数

6
推荐指数
1
解决办法
2164
查看次数

使用SQLite In Memory配置测试NHibernate时,如何创建另一个数据库?

我们有一个使用NHibernate/FluentNHibernate的应用程序,它MsSqlConfiguration.MsSql2008.ConnectionString指向我们的SQL环境.SQL服务器有几个数据库,我们可以使用如下的约定连接到不同的数据库:

public class FactseDatabaseConvention : IClassConvention
{
    public void Apply(IClassInstance instance)
    {
        if (instance.EntityType.Namespace.EndsWith("Model.OtherEntities"))
        {
            instance.Schema("OtherDatabase.dbo");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这有效,并生成正确的查询来访问OtherDatabase.当我们想要使用SQLiteConfiguration.Standard.InMemory()SessionFactory 进行测试时会出现问题.SQLite准备时,Persistence测试失败:

System.Data.SQLite.SQLiteException : SQL logic error or missing database
unknown database OtherDatabase
Run Code Online (Sandbox Code Playgroud)

这是它生成的命令:

create table OtherDatabse.dbo_my_other_entity_table (
        Id UNIQUEIDENTIFIER not null,
        ... other properties
)
Run Code Online (Sandbox Code Playgroud)

有没有办法我可以改变我SQLiteConfiguration创建2个内存数据库,如果是这样,怎么样?或者我应该创建一个单独的会话来测试这些其他实体?

sqlite nhibernate fluent-nhibernate nhibernate-configuration

5
推荐指数
1
解决办法
1238
查看次数

在NHibernate.Linq查询中的'OFFSET'错误附近获取不正确的语法

我在我的ASP.NET MVC 4.0应用程序中遇到以下错误NHibernate v4.0.0 (.Net Framework 4.0).NHibernate.Linq查询中显示此错误

Incorrect syntax near 'OFFSET'.
Invalid usage of the option FIRST in the FETCH statement.
Run Code Online (Sandbox Code Playgroud)

在这一行

Line 23:         public IList<Post> Posts(int pageNo, int pageSize)
Line 24:         {
Line 25:             var posts = _session.Query<Post>()  //here
Line 26:                                   .Where(p => p.Published) 
Line 27:                                   .Skip(pageNo * pageSize)
Run Code Online (Sandbox Code Playgroud)

我在SO和其他网站上发现了一些类似的帖子.但是,他们建议使用SQL SERVER 2012而不是2008.是的,我的sql server版本是2008.但是,我已经使用ASP.NET MVC 5 (.Net Framework 4.5)和创建了另一个应用程序NHibernate v3.3.1,它在同一个数据库和相同的sql server版本中运行良好.

一些类似的帖子:

  1. "'OFFSET'附近的语法不正确"modift sql comm 2012至2008
  2. mssql …

c# sql-server nhibernate asp.net-mvc nhibernate-configuration

3
推荐指数
1
解决办法
3059
查看次数

为什么NHibernate说我的过滤器没有配置?

我正在尝试在NHibernate中使用全局过滤器,据我所知,我正在完成所有教程所做的事情,但我得到了一个例外.

我的.hbm.xml文件包含以下内容:

...
<class name="NHibernateSandbox.Foo, NHibernateSandbox" table="Foo">
    ...
    <property column="Content" type="String" name="Content" not-null="true" length="100" />
    <property column="Deleted" type="Boolean" name="Deleted" not-null="true" />
    <filter name="Foo_Nondeleted" condition="Deleted = false" />
</class>
Run Code Online (Sandbox Code Playgroud)

然后我有一个简单的测试类:

Configuration cfg = new Configuration();
cfg.Configure();

using (ISessionFactory sf = cfg.BuildSessionFactory()) {
    using (ISession session = sf.OpenSession()) {
        session.EnableFilter("Foo_Nondeleted");
        IQuery query = session.CreateQuery("FROM NHibernateSandbox.Foo");
        foreach (Foo foo in query.List<Foo>()) {
            Console.WriteLine(foo.Content);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我删除EnableFilter它按预期工作的行:打印已删除和未删除的行.但是,有了这EnableFilter行,我得到了一个N​​HibernateException

No such filter configured [Foo_Nondeleted]
  at NHibernate.Impl.SessionFactoryImpl.GetFilterDefinition(String filterName)
  at NHibernate.Impl.SessionImpl.EnableFilter(String filterName)
  at …
Run Code Online (Sandbox Code Playgroud)

nhibernate nhibernate-configuration

1
推荐指数
1
解决办法
1185
查看次数