NHibernate HiLo生成和SQL 2005/8模式 [英] NHibernate HiLo generation and SQL 2005/8 Schemas

查看:79
本文介绍了NHibernate HiLo生成和SQL 2005/8模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我手上有一个问题,我花了几天时间寻找无济于事的答案...

I have an issue on my hands that I've spent several days searching for an answer to no avail...

我们正在使用HiLo Id生成,并且只要实体表与hibernate_unique_key表处于同一架构中,一切似乎都可以正常工作.

We're using HiLo Id generation, and everything seems to be working fine, as long as the entity table is in the same schema as the hibernate_unique_key table.

表结构非常简单.我在db中有hi值表,名称为dbo.hibernate_unique_key. dbo模式中也有几个实体表,它们可以正常工作.然后,我们在联系人"模式下有表格(例如Contact.Person和Contact.Address).

The table structure is pretty simple. I have my hi value table in the db as dbo.hibernate_unique_key. Several entity table are also in the dbo schema, and they work without issue. Then we have tables under the "Contact" schema (such as Contact.Person and Contact.Address).

在人员映射文件中:

<class name="Person" table="Person" schema="Contact">
<id name="Id" unsaved-value="0">
  <generator class="hilo">
    <param name="max_lo">100</param>
  </generator>
</id>
...

当我尝试插入一个Person实体时,出现错误消息无效的对象名称'Contact.hibernate_unique_key'.该错误肯定很清楚.因此我添加:

When I try to insert a Person entity, I get an error of "Invalid object name 'Contact.hibernate_unique_key'. That error is certainly clear enough. So I add:

<param name="schema">dbo</param>

到我的映射文件/生成器元素.现在,在建立SessionFactory时,我得到一个已经添加了具有相同键的项目".错误.所以现在我有点卡住了.我不能让HiLo生成器没有模式,因为它从类中拾取了模式,并且由于已经添加了模式,所以我无法指定模式(大概是因为它是我的XML cfg文件中标识的"default_schema" ).

to my mapping file/generator element. Now, when the SessionFactory is built, I get a "An item with the same key has already been added." error. So now I'm a bit stuck. I can't leave the HiLo generator without a schema, because it picks up the schema from the Class, and I can't specify the schema because it's already been added (presumably because it's my "default_schema" as identified in my XML cfg file).

我在这里完全被软管塞住了吗?我是否必须

Am I completely hosed here? Must I either

A)将我所有的表都保留在dbo模式或

A) Keep all my tables in the dbo schema or

B)为数据库中的每个唯一模式创建一个单独的HiLo Key表吗?

B) Create a separate HiLo Key table for each unique schema in the DB?

这两种情况都不适合我的应用程序,因此我希望我可以修复"映射文件以解决此问题.

Neither of those scenarios is particularly palatable for my application, so I'm hoping that I can "fix" my mapping files to address this issue.

推荐答案

我认为解决方案 B 没什么问题.行为将几乎相同.

I don't think there's anything wrong with solution B. Behavior will be pretty much the same.

这篇关于NHibernate HiLo生成和SQL 2005/8模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆