Oracle Native ID generation with NHibernate
来源:互联网 发布:淘宝app怎么卖二手东西 编辑:程序博客网 时间:2024/06/02 02:03
Native ID generation with NHibernate
原文出处 : http://davybrion.com/blog/2007/07/native-id-generation-with-nhibernate/
iwas looking for a way to define the mapping of an ID field so it wouldwork on both Oracle and SQL Server… In case of Oracle, it would have touse a Sequence that i can define. On Sql Server, it should use anIdentity column. Luckily, NHibernate offers just that… the ‘native’ IDgenerator uses identity on sql server and a sequence on Oracle.
Unfortunately the ‘native’ generator is hardly documented in theNhibernate reference documentation so it wasn’t really clear to mewhich sequence would be used, or how i could define my own. All thedocumentation says is basically:
For cross-platform development, the native strategy willchoose from the identity, sequence and hilo strategies, dependent uponthe capabilities of the underlying database.
So how can you define which sequence it should use in case ofOracle? Very simple actually… turns out you just define the sequencename in the same way you would as if you set it to use the ’sequence’generator.
So here’s how you do it:
<id name="Id" column="CustomerId" type="long" unsaved-value="-1"
access="field.camelcase-underscore">
<generator class="native" >
<param name="sequence">sq_customer</param>
</generator>
</id>
On Oracle, it will use the sq_customer sequence whereas on SQLServer the sequence parameter will be ignored and it will use theIdentity setting of the column that was defined as the ID (in thiscase, CustomerId’s Identity settings)
当访问的是MS SQLServer时,<param name="sequence">sq_customer</param>会被忽略,而使用MS SQLServer的Identity方式来生成ID;当访问的时Oracle数据库时,使用
<param name="sequence">sq_customer</param>中的squence sq_customer来生成Id.
- Oracle Native ID generation with NHibernate
- Using MemCached with NHibernate
- How to create id with AUTO_INCREMENT on Oracle?
- Using NHibernate with Multiple Databases
- Model change control with NHibernate
- NHibernate 与Oracle 点滴
- NHibernate & oracle: ORA-01045
- How ClickOnce Manifest Generation works with MSBuild
- How to deal with generation gap
- Client Ids generation with ASP.NET 4.0
- SOAP views with on-demand WSDL generation
- 代码生成(Code Generation with Bake)
- Working with JasperReports for easy report generation
- Chinese Poetry Generation with Recurrent Neural Networks
- Chinese Poetry Generation with Recurrent Neural Networks
- Art Generation with Neural Style Transfer
- Art Generation with Neural Style Transfer
- NHibernate composite-id联合主键配置
- C#编码好习惯
- response.sendRedirect()和request.getRequestDispatcher().forward(request,response)的区别
- windows live messenger 2009 去广告和多开的方法
- [DirectShow] 001 - Introduction to DirectShow Application Programming
- aaaaaaaaaa
- Oracle Native ID generation with NHibernate
- 最长子序列的更优解法
- JNDI中几个基本名词的解释
- 解决访问TFS时“文档”和“报告”打叉的问题
- 软件公司是怎么消亡的
- The Oracle server’s NLS_LANG
- log4Net使用
- 什么是CIF/4CIF/QCIF/D1?
- (求助 大拿们)linux下自动部署jsp项目