CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Paul Laudeman

Helping You to Make "Smart Clients" Smarter!

NHibernate 0.8 released

NHibernate 0.8 has been released! If you haven't heard of NHibernate before, it is a .NET port of the popular Hibernate for Java object relational persistence library for databases. While I still haven't found a project to use NHibernate for my data access needs, it does seem like a very promising technology and is fairly well supported.

I'd be interested in hearing about any positive or negative experiences in using this for production applications. If you've used it before and have any thoughts to share, please leave a comment or drop by the CodeBetter.com forums and share your thoughts.

Technorati Tags:  


Published May 07 2005, 03:46 PM by paul.laudeman
Filed under:

Comments

Sam said:

Well, I've mentioned it before, but I have it running in a service for a few weeks now. It's worked out wonderfully. I'm also using it in a new web-project. This one isn't using a legacy database, so I'm actually implementing full object graphs this time. Again, it's great, and once you figure out that you get ITypes through TypeFactory, hql is pretty darn easy too. :)

What isn't so easy is reporting. Of course it's not built for that, but just the same, don't automatically assume that just because you've got objects for each entity that you can then easily report on them. Sometimes it works, sometimes it's more trouble than whipping out ADO.NET. (This is a demo project, so whatever gets the job done fastest in this case, it's largely not production quality wrt design.)

The one major annoyance I've had is that HQL makes it very easy to query for reports, but I haven't seen an example of binding to DataGrids. For example:

IList rows = session.Find("select c.Name, c.Purchases.Posted, c.Purchases.Amount From Customer as c Where c.Id = ?", id, TypeFactory.GetGuid());

This gives you an array of strongly-typed objects, string for name, DateTime for Posted, decimal for Amount in this example. I haven't figured out how to bind this though. (I haven't worked on ASP.NET in over a year is my excuse ;) ) So, I create a DataTable with the columns, and then add each row. This works well enough, but I only did this for one report since it's not any fewer lines of code, or less hard-coded than just writing a static method that executes some ado.net and returns a DataSet.

Another small annoyance is that the Nullables library doesn't override .ToString() to match the primitive types, so for example, you can't format a NullableDateTime with standard datetime format strings without calling NullableDateTime.Value.ToString("f"). Again time is very short so it may implement IFormattable or something and I just didn't notice (haven't used it much since I'm rarely involved in such reporting apps).

If anybody could comment on the above I would much appreciate it.

Anyways, overall, I really like it, and as the docs improve, and I get more time with it, I hope to learn some of the ins and outs better.
# May 7, 2005 6:14 PM

Christopher Steen said:

Link Dump - 3
# May 9, 2005 7:44 PM

renee said:

New to OR mappers and I have to collect information on many of them. Need to know if NHibernate 0.8 supports

Oracle 8 and 9
DB2 7 and 8
SQL server, and access.

let me know,
thanks.
# May 18, 2005 8:12 AM

Ja said:

I have used NHibernate in two small enterprise ASP.NET intranet apps. There are almost no bugs and everything works as expected. The overall performace is also good, but somewhere is still required to use old SqlCommands.

The reason why classic SQL is sometimes unavoidable is because ADO.NET does not support batch commands like in JDBC and NHibernate sends separate command to database for each updated record - with poor performace. There is also no support for partial resultsets (pagination) in MS SQL 2000, when you want to display only a subset of a resultset NHibernate fetches all rows from database and discards the unneeded ones. This also affects performace, but only when using MS SQL, other common databases supports paging via ROWNUMS or SELECT LIMIT.

The conclusion is, you can safely use NHibernate even in commercial apps. I experimeced really faster software develpment wiht Hibernate at all.
# May 20, 2005 5:39 AM

hulisani said:

I have used nHibernate in a fairly large project and it did not encounter any bugs. And the performance was also good so i think it is a very handy tool to use.
# June 28, 2005 1:02 AM

DALT said:

I am using nHibernate in moderately large project (30 - 40 business objects) and it works fine. It is ASP.NET project and I am using it together with Maverick.net (MVC framework) for clear separation of app logic from presentation.

For getting data I have used DAO pattern (static methods which are returning bo or collection) - thus no need for opened nhib session on the page scope.

# July 14, 2005 7:19 AM

abhi said:

I am trying to fill a data repeater using nhibernate i am trying to figure out how paging can i implement paging, since i am not using any dataset.., any help wud be  greatly appreciated

# November 8, 2006 10:16 PM

paul.laudeman said:

Hi Abhi,

My friend Ayende posted this comment[1] to Jeffrey's blog:

Paging with NHibernate: session.CreateQuery("from Post") .SetFirstResult(10) .SetMaxResults(10).List();

Also, feel free to check out some of my bookmarks on NHibernate in general, too:

http://del.icio.us/plaudeman/nhibernate

Also, please be sure you are running the most recent release[2] of NHibernate (currently 1.0.3, or 1.20 beta 1).

[1]

http://codebetter.com/blogs/jeffrey.palermo/archive/2006/11/03/We_2700_ll-see-Microsoft_2700_s-OR-Mapper-soon-_2D00_-level-100.aspx#comments

[2] http://hibernate.org/6.html

# November 9, 2006 7:00 AM

abhi said:

thanks a lot paul, I have asp.net application , which is up and running on the dev server, i am trying to set the application on my local machine, it builds fine on my machine but when i try and access the default page i get the following error.

Server Error in '/TSJon.crtd.website' Application.

--------------------------------------------------------------------------------

could not interpret type: Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.MappingException: could not interpret type: Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate

Source Error:

Line 66:

Line 67: /// <summary></summary>

Line 68: public readonly USIGateway USIGateway = new USIGateway();

Line 69:

Line 70: /// <summary></summary>

Source File: C:\Inetpub\wwwroot\scj.crtd\webcode\Web\HttpApplicationContext.cs    Line: 68

[MappingException: could not interpret type: Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate]

  NHibernate.Cfg.Binder.GetTypeFromXML(XmlNode node) +140

  NHibernate.Cfg.Binder.BindSimpleValue(XmlNode node, SimpleValue model, Boolean isNullable, String path, Mappings mappings) +15

  NHibernate.Cfg.Binder.PropertiesFromXML(XmlNode node, PersistentClass model, Mappings mappings) +870

  NHibernate.Cfg.Binder.BindRootClass(XmlNode node, RootClass model, Mappings mappings) +2660

  NHibernate.Cfg.Binder.BindRoot(XmlDocument doc, Mappings model) +616

  NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc) +111

  NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream) +107

  NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering) +256

  NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) +7

  TSJon.Crtd.ApplicationContext..ctor()

  TSJon.Crtd.Web.HttpApplicationContext..ctor() in C:\Inetpub\wwwroot\scj.crtd\webcode\Web\HttpApplicationContext.cs:68

[TargetInvocationException: Exception has been thrown by the target of an invocation.]

  System.RuntimeType.CreateInstanceImpl(Boolean publicOnly) +0

  System.Activator.CreateInstance(Type type, Boolean nonPublic) +66

  System.Activator.CreateInstance(Type type) +7

  TSJon.Crtd.Nested.CreateContext()

  TSJon.Crtd.Nested..cctor()

[TypeInitializationException: The type initializer for "Nested" threw an exception.]

  TSJon.Crtd.ApplicationContext.get_Current()

  TSJon.Crtd.Web.HttpApplicationContext.get_Current() in C:\Inetpub\wwwroot\scj.crtd\webcode\Web\HttpApplicationContext.cs:28

  TSJon.Crtd.Web.HttpApplicationModule.Application_EndRequest(Object sender, EventArgs e) in C:\Inetpub\wwwroot\scj.crtd\webcode\Web\HttpApplicationModule.cs:32

  System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +60

  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +87

# November 10, 2006 9:46 AM

abhi said:

i am mapping the fields to a char column of length one, but  n-hibernate throws the following error message.

could not interpret type:char

<property name="P1_Var" column="P1" type="char(1) />

# November 29, 2006 1:38 PM

paul.laudeman said:

Abhi,  

Try changing your property statement to the following:

<property name="P1_Var" column="P1" type="String" length="1" />

# November 29, 2006 5:51 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors