Would you use NHibernate for a project with a legacy database, which is partly out of your control?
Asked Answered
H

3

5

For me the answer is currently: No, I would use iBatis, because NHibernate is a pain, when the database model and the object model are not in synch. If I don't have full control over the database I end up with a lot of work.

Why do I ask?

Well, first of all: I never used NHibernate. I just know it from the surface. I have read about the advantages of iBatis for legacy databases.

Second: Recently I had a discussion with someone who worked with Hibernate (jep, without 'N' before Hibernate). He told me that the ORM frameworks are now pretty advanced and advocated Hibernate. Since I was not interested in NHibernate, I didn't keep track of the recent developments.

Maybe I its time to rethink my answer, or not?

Halonna answered 17/1, 2009 at 22:57 Comment(1)
This would have been my next question on stackoverflow - thanks for asking !Theophylline
K
5

iBatis is certainly easy to map objects to legacy database systems.

More recently NHibernate 1.2 and 2.0 have a feature set that may make you rethink iBatis.

NHibernate works with composite keys, which can occur frequently in older databases, they aren't always pleasant to work with but support is there for this.

NHibernate can utilise Stored Procedures for CRUD operations on entities, also database views.

Collections can be custom stored procedures or SQL queries. Collections can use the property-ref attribute when the Foreign Key relationship doesn't map directly to the Primary Key on the other side.

Some of these features may take away from the performance/power of nhibernate, ie Lazy Loading with property-ref doesn't work (at all?), but is most cases there are reasons for this.

Other points: (which aren't really related to your legacy database but still can help decide on a technology choice)

The Nhibernate community appears much richer than the iBatis. I'm on both lists and the volume of support for NHibernate is quite large compared to the iBatis group. So support should be easier.

Also there is a growing amount of contrib/3rd party tools for NHibernate. Things like The NHibernate Profiler, the Nhibernate Query Analyzer, NHibernate Contrib, Fluent NHibernate to name a few.

Perhaps you can expand on what advantages you believe iBatis currently has. NHibernate has certainly been quite active recently and has gained many new features, a lot of which do assist in legacy/hard to modify schemas.

And to answer the question, yes we do use NHibernate with legacy databases that have awful relationships, composite keys, broken relationships. We still also have a small amount of code based on iBatis. We no longer write any more iBatis code though.

Kurys answered 20/1, 2009 at 7:25 Comment(0)
L
1

Yes, consider NHibernate. It's the gold standard for a reason. I have heard that iBATIS supports crazy mapping possibilities, but with NHibernate's IUserType you can map anything, even really strange columns.

@Ahmad, the entire point of ORM is to prevent a tight coupling between your objects and your schema. If you have this problem you're doing it wrong.

Also, with NHibernate there are plenty of options for custom queries, formula properties and stored procedures. HQL is extremely powerful and Criteria is flexible.

I think you'll be doing your clients a disservice if you don't at least spike NHibernate.

Layla answered 20/1, 2009 at 0:5 Comment(1)
How about really crazy joins between tables? Because it's partly a legacy database, there will be also the need for some handrolled SQL statements.Halonna
B
0

I've been using nHibernate in an existing application. I use it for all new development, I have no intention of porting the existing stuff over either there just isn't a compelling reason but for new stuff on the project it works great.

If you are going to port the code over then you should be able to change the database to match better with your domain model, without much impact (depending on how leaky your database is ie who access it). Changing the domain model would impact the application however.

Brighten answered 17/1, 2009 at 23:16 Comment(1)
It's not a code port. The many parts of the old application remainsand functionality should be added. The database structure is partly out of my control (because of the old parts of the application and because of dependencies from other existing ones).Halonna

© 2022 - 2024 — McMap. All rights reserved.