NHibernate
Encyclopedia
NHibernate is an object-relational mapping
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...

 (ORM) solution for the Microsoft .NET
.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

 platform: it provides a framework
Software framework
In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by user code, thus providing application specific software...

 for mapping an object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 domain model
Domain model
A domain model in problem solving and software engineering can be thought of as a conceptual model of a domain of interest which describes the various entities, their attributes, roles and relationships, plus the constraints that govern the integrity of the model elements comprising that problem...

 to a traditional relational database
Relational database
A relational database is a database that conforms to relational model theory. The software used in a relational database is called a relational database management system . Colloquial use of the term "relational database" may refer to the RDBMS software, or the relational database itself...

. Its purpose is to relieve the developer from a significant portion of relational data persistence
Persistence (computer science)
Persistence in computer science refers to the characteristic of state that outlives the process that created it. Without this capability, state would only exist in RAM, and would be lost when this RAM loses power, such as a computer shutdown....

-related programming tasks. NHibernate is free
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 as open source software that is distributed under the GNU Lesser General Public License
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

. NHibernate is a port of the popular Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 O/R mapper Hibernate
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

 to .NET. NHibernate provides transparent persistence for Plain Old CLR Object
Plain Old CLR Object
Plain Old CLR Object or POCO is a play on the term POJO, from the Java EE programming world, and is used by developers targeting the Common Language Runtime of the .NET Framework....

s (POCOs). The only strict requirement for a persistent class is a no-argument constructor
Constructor (computer science)
In object-oriented programming, a constructor in a class is a special type of subroutine called at the creation of an object. It prepares the new object for use, often accepting parameters which the constructor uses to set any member variables required when the object is first created...

, which does not have to be public. (Proper behavior in some applications also requires special attention to the Equals and GetHashCode methods.)

Feature summary

NHibernate's primary feature is mapping from .NET classes to database tables (and from CLR
Common Language Runtime
The Common Language Runtime is the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time compilation, the CLR compiles the intermediate language code known as CIL into the machine instructions...

 data types to SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

 data types). NHibernate also provides data query and retrieval facilities. NHibernate generates the SQL commands and relieves the developer from manual data set handling and object conversion, keeping the application portable to most SQL databases, with database portability delivered at very little performance overhead.

NHibernate provides transparent persistence for Plain Old CLR Objects (POCOs). The only strict requirement for a persistent class is a no-argument constructor, which does not have to be public. (Proper behavior in some applications also requires special attention to the Equals and GetHashCode methods.[1])

History

NHibernate was started by Tom Barrett, and later picked up by Mike Doerfler and Peter Smulovics. Now Fabio Maulo is the project leader. At the end of 2005, JBoss
JBoss (company)
JBoss is a division of Red Hat, Inc.. It specializes in open-source middleware software.The company profits from a service-based business model. JBoss employ a Professional Open Source business model where the core developers of projects make a living and offer their services...

, Inc. (now part of Red Hat
Red Hat
Red Hat, Inc. is an S&P 500 company in the free and open source software sector, and a major Linux distribution vendor. Founded in 1993, Red Hat has its corporate headquarters in Raleigh, North Carolina with satellite offices worldwide....

) hired Sergey Koshcheyev, the then lead developer of NHibernate, to work full-time on its future versions. At the end of 2006 JBoss stopped the support to this project; it is now entirely developed and led by the community.

Version 1.0 mirrored the feature set of Hibernate 2.1, as well as a number of features from Hibernate 3.

NHibernate 1.2.1, released in November 2007, introduced many more features from Hibernate 3 and support for .NET 2.0, stored procedure
Stored procedure
A stored procedure is a subroutine available to applications that access a relational database system. A stored procedure is actually stored in the database data dictionary.Typical uses for stored procedures include data validation or access control mechanisms...

s, generics, and nullable types.

NHibernate 2.0 was released August 23, 2008. It is comparable to Hibernate 3.2 in terms of features. With the version 2.0 release, NHibernate dropped support for .NET 1.1.

NHibernate 2.1 was released July 17, 2009.
NHibernate 3.0 was released on December 04, 2010 and is the first version to use .NET 3.5. Introduces integrated LINQ
LINQ
Linq is a word-based card game from Endless Games, introduced at the American International Toy Fair in 2005.Game play requires at least four players, two of whom are dealt cards with the same word, while the others receive blanks. The goal is to gain points by correctly naming the players with...

 support and also strongly typed criteria-like API called QueryOver, new AST
Abstract syntax tree
In computer science, an abstract syntax tree , or just syntax tree, is a tree representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code. The syntax is 'abstract' in the sense that it...

-based parser for NHibernate's HQL (Hibernate Query Language) engine, support for lazy loading columns.

NHibernate 3.2 has been released recently.

What is new in NHibernate 3.2

Some of the new Features are
  • Mapping by code: fluent configuration, no more .hbm.xml files required;
  • Subselect: ability to map SQL views as entities;
  • HQL paging: TAKE and SKIP on HQL;
  • Integrated bytecode provider: one less DLL to deploy.

Contributions

As open source software, NHibernate has received many contributions from its users. Most of them are directly integrated as internal features. Others are provided by the users as utilities and documentation.

Implementation of LINQ
Language Integrated Query
Language Integrated Query is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, although ports exist for Java, PHP and JavaScript....

 has allowed Language Integrated Query use with NHibernate.

Sample

Here a code snippet to save and retrieve an object using NHibernate:

////Save a Customer
using (var session = sessionFactory.OpenSession)
{
using (ITransaction transaction = session.BeginTransaction)
{
session.Save(new Customer { Id = Guid.NewGuid, FirstName = "Bill", Age = 50 });
transaction.Commit;
}
}

////Retrieve the Customer
using (var session = sessionFactory.OpenSession)
{
var customer = session.Query.Single(c => c.Id

id);
}


External links
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK