
NHibernate 2.0
NHibernate源于非常优秀的基于Java的Hibernate关系型持久化工具。可是从2007年11月26日发布的1.2.1GA版本不是很好的支持VS2008。今天负责NHibernate开发的Ayende Rahien发布了NHibernate 2.0.0 Alpha 1,我们可以从这里下载,相信不久正式版会更好,先下载尝鲜一下。
下载看看源代码,其中很多代码都是用VS2008写的。并附了两个例子。
下面列表列出了一些改进:
新特性:
- Add join mapping element to map one class to several tables
- <union> tables and <union-subclass> inheritance strategy
- HQL functions 'current_timestamp', 'str' and 'locate' for PostgreSQL dialect
- VetoInterceptor - Cancel Calls to Delete, Update, Insert via the IInterceptor Interface
- Using constants in select clause of HQL
- Added [ Table per subclass, using a discriminator ] Support to Nhibernate
- Added support for paging in sub queries.
- Auto discovery of types in custom SQL queries
- Added OnPreLoad & OnPostLoad Lifecycle Events
- Added ThreadStaticSessionContext
- Added <on-delete> tag to <key>
- Added foreign-key="none" since the Parent have not-found="ignore". (not relevant to SQL Server)
- Added DetachedQuery
- ExecuteUpdate support for native SQL queries
- From Hibernate:
- Ported Actions, Events and Listeners
- Ported StatelessSession
- Ported CacheMode
- Ported Statistics
- Ported QueryPlan
- Ported ResultSetWrapper
- Ported Structured/Unstructured cache
- Ported SchemaUpdate
- Ported Hibernate.UserTypes
- Ported Hibernate.Mapping
- Ported Hibernate.Type
- Ported EntityKey
- Ported CollectionKey
- Ported TypedValue
- Ported SQLExceptionConverter
- Ported Session Context
- Ported CascadingAction
Breaking changes:
- Changed NHibernate.Expression namespace to NHibernate.Criterion
- Changed NHiberante.Property namespace to NHiberante.Properties
- No AutoFlush outside a transaction - Database transactions are never optional, all communication with a database has to occur inside a transaction, no matter if you read or write data.
- <nhibernate> section is ignored, using <hibernate-configuration> section (note that they have different XML formats)
- Configuration values are no longer prefixed by "hibernate.", if before you would specify "hibernate.dialect", now you specify just "dialect"
- IInterceptor changed to match the Hibernate 3.2 Interceptor - interface changed
- Will perform validation on all named queries at initialization time, and throw if any is not valid.
- NHibernate will return long for count(*) queries on SQL Server
- SaveOrUpdateCopy return a new instance of the entity without change the original.
- INamingStrategy interface changed
- NHibernate.Search - Moved Index/Store attributes to the Attributes namespace
- Changes to IType, IEntityPersister, IVersionType - of interest only to people who did crazy stuff with NHibernate.
- <formula> must contain parenthesis when needed
- IBatcher interface change
Fixed bugs:
- Fixing bug with HQL queries on map with formula.
- Fixed exception when the <idbag> has a <composite-element> inside; inside which, has a <many-to-one>
- Multi criteria doesn't support paging on dialects that doesn't support limiting the query size using SQL.
- Fixed an issue with limit string in MsSql2005 dialect sorting incorrectly on machines with multiple processors
- Fixed an issue with getting NullReferenceException when using SimpleSubqueryExpression within another subexpression
- Fixed Null Reference Exception when deleting a <list> that has holes in it.
- Fixed duplicate column name on complex joins of similar tables
- Fixed MultiQuery force to use parameter in all queries
- Fixed concat function fails when a parameter contains a comma, and using MaxResults
- Fixed failure with Formula when using the paging on MSSQL 2005 dialect
- Fixed PersistentEnumType incorrectly assumes enum types have zero-value defined
- Fixed SetMaxResults() returns one less row when SetFirstResult() is not used
- Fixed Bug in GetLimitString for SQL Server 2005 when ordering by aggregates
- Fixed SessionImpl.EnableFilter returns wrong filter if already enabled
- Fixed Generated Id does not work for MySQL
- Fixed one-to-one can never be lazy
- Fixed FOR UPDATE statements not generated for pessimistic locking
改进:
- Added Guid support for Postgre Dialect
- Added support for comments in queries
- Added Merge and Persist to ISession
- Support IFF for SQL Server
- IdBag now work with Identity columns
- Multi Criteria now uses the Result Transformer
- Handling key-many-to-one && not-found
- Can now specify that a class is abstract in the mapping.
Guidance:
- Prefer to use the Restrictions instead of the Expression class for defining Criteria queries.
Child projects:
- Added NHibernate.Validator
- Added NHibernate.Shards
- NHibernate.Search updated match to Hibernate Search 3.0
Criteria API:
- Allow Inspection, Traversal, Cloning and Transformation for ICriteria and DetachedCriteria
- Introduced CriteriaTransformer class
- GetCriteriaByPath, GetCriteriaByAlias
- Added DetachedCriteria.For<T>
- Added Multi Criteria
- Projections can now pass parameters to the generated SQL statement.
- Added support for calling Sql Functions (HQL concept) from projections (Criteria).
- Added ConstantProjection
- Added CastProjection
- Can use IProjection as a parameter to ICriterion
Better validation for proxies:
- Now supports checking for internal fields as well
- Updated Castle.DynamicProxy2.dll to have better support for .NET 2.0 SP1
SQL Lite:
- Support for multi query and multi criteria
- Supporting subselects and limits
- Allowed DROP TABLE IF EXISTS semantics
PostgreSQL (Npgsql):
- Enable Multi Query support for PostgreSQL
FireBird:
- Much better overall support
Batching:
- Changed logging to make it clearer that all commands are send to the database in a single batch.
- AbstractBatcher now use the Interceptor to allow the user intercept and change an SQL before it's preparation
Error handling:
- Better error message on exception in getting values in Int32Type
- Better error message when using a subquery that contains a reference to non existing property
- Throws a more meaningful exception when calling UniqueResult<T>() with a value type and the query returns null.
- Overall better error handling
- Better debug logs
Refactoring:
- Major refactoring internally to use generic collections instead of the non generic types.
- Major refactoring to the configuration and the parsing of hbm files.
Factories:
- Added ProxyFactoryFactory
- Added BatchingBatcherFactory
作者:李永京(YJingLee's Blog)
出处:http://lyj.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted @ 2008-03-31 17:11
李永京 阅读(4749)
评论(39) 编辑 收藏 网摘 所属分类:
NHibernate
发表评论
#3楼[
楼主]2008-03-31 17:38 |
@Anders Cui
呵呵,第一时间知道,就写篇文章发到首页了,把这消息分享给更多的人!
#4楼[
楼主]2008-03-31 17:40 |
@RicCC
是的啊,我想到正式版会更出色,可以同LINQ同媲美了。或许比LINQ更好!
@李永京
NH跟LINQ不太好比较的,要说是用方便上如果NH能将hibernate3的HQL实现早点导入过来可能会更好
官方的特性列表里面说2.0会提供LINQ支持,文章的列表里面好像没有,是这个Alpha版本还没有实现吗
不知道LINQ,NHibernate有什么区别,有了LINQ,不知道 NHibernate的路会怎么样?
#7楼[
楼主]2008-03-31 17:59 |
@RicCC
都是ORM。LINQ有LINQ to SQL,NHibernate有NHibernate to LINQ。比较的是效率,开发速率等等了。
#8楼[
楼主]2008-03-31 18:00 |
@生鱼片
呵呵,这就要看NHibernate开发的情况了,不过从过去看来,一直是挺优秀的!
#9楼[
楼主]2008-03-31 18:05 |
@RicCC
是啊,看似没有LINQ支持,晚上看看源代码。。。
#12楼[
楼主]2008-03-31 19:07 |
@代码乱了
确实!正式版我想更强大了
关注啊,现在的项目用的就是NH,希望能达到在JAVA世界里的水平
#14楼[
楼主]2008-03-31 19:19 |
@brightwang
呵呵,用VS2008体验一把!
#17楼[
楼主]2008-03-31 22:04 |
@黎波
o(∩_∩)o...
#18楼[
楼主]2008-03-31 22:06 |
@Kevin Li
光顾一下??o(∩_∩)o...
2008写的?难道这个版本必须要有framework 3以上支持?
不是已经有人在做LINQ to NHibernate了吗?
关注,现在还在用1.2.0。如果Release了,会考虑迁移的。
有没有NStruts啊,这个也可以啊,在小公司也可以快速的开发啊,对了其是MVC就可以说成是NStruts啊,
我觉得这个东西很麻烦,好多配置文件,大概用codesmith生成比较方便,可惜偶不会。。。。
#24楼[
楼主]2008-04-01 12:08 |
@Leem
不需要,只是把代码移植到2008上的,大多数还有2005项目。
#25楼[
楼主]2008-04-01 12:13 |
#26楼[
楼主]2008-04-01 12:14 |
@小瑞克
配置是有些麻烦。以后我试试模板
#27楼[
楼主]2008-04-01 12:15 |
@caodaiming
不清楚这个,观望中~~~
#28楼[
楼主]2008-04-01 12:15 |
@冰隼
现在体验一下!到正式版相信会更加出色!
无法访问sourceforge,其他人有没有出现过这个问题
#30楼[
楼主]2008-06-26 00:24 |
@昊子
经过月光对路由的测试,经过电信骨干网的某个路由器时,访问被阻拦,因此相信这是电信的所为,中国电信对于专业技术类型网站的屏蔽令人感到不解,上一次的误封还是发生在2006年,这一次不知道又是为了什么原因。
当然,希望SourceForge的无法访问不是因为这个项目的问题,然而不可否认的是,对于SourceForge这样一个庞大的软件开源项目的屏蔽,会对中国的软件发展产生严重的阻碍,影响中国的科技发展和进步。
另外发现hibernate.org本身对NH的文档不很重视,下载链接也还是1.2 GA,完全没有提到2.0 beta。
不知道是不是可以理解为NH本身没有团队支持
#32楼[
楼主]2008-06-27 14:15 |
@昊子
这是测试版的,内部测试的,我想到正式版之后才可以公开发布的。
有 必要开一个Nhiberate Sample
专题 每个特性都值得介绍
#34楼[
楼主]2008-07-01 09:24 |
@gakaki
不必了吧,这些特性只有在使用过程中才能慢慢体会。
我有一个问题不清楚,也是我值不值得研究它的一个主要的问题,比如A类与B类关联,B类与C类关联.如果在不采用延迟加载的时候,如果要一起把这相关的三个类都加载了,是用一个SQL语句(使用关联),还是要使用三条语句加载(如果是1对多的关系,那调用的次数要呈几何级增加)?我还没有研究NHibernate,希望楼主能给我讲解一下,谢谢.
to 35楼
建议你先看看书,孙卫琴的 精通hibernate。
aspx@hotmail.com
#38楼[
楼主]2008-07-11 20:51 |
@piaoxue
谢谢你的回复,一直没有时间上网
#39楼[
楼主]
2008-07-11 20:54 |
@毁于随
你可以先看看源码中的例子,可以很快入门/这个问题在NH中可以很好的解决。提供了映射关系支持/