NHibernate to replace SQL code

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
12/28/2008 4:44:51 AM
Gravatar
Total Posts 1

NHibernate to replace SQL code

 Is there a reason NHibernate is not used to replace the SQL code for several SQL server platforms?

12/28/2008 6:47:42 AM
Gravatar
Total Posts 18439

Re: NHibernate to replace SQL code

Hi,

Yes, there is a reason. The reason is I'm one of those (apparently minority) who does not think OR mappers make the best architecture. I think its great for rapid development but I don't think it produces the best architecture. If that is important to you to use NHibernate, I would refer you to the Cuyahoga project which uses it.

Best,

Joe

12/29/2008 7:22:37 AM
Gravatar
Total Posts 55

Re: NHibernate to replace SQL code

Well, there was and is awfully lot of Internet flaming between followers of ORM paradigm and sproc people, especially in the first part of this decade. Although majority of development and maintenance today is still done using sproc paradigm, it seems there's slow but steady decline of that paradigm and slow but steady acceptance of ORM.

I'm not inclined towards such flaming, although I admit that I'm leaving sproc paradigm too, slowly but steady - after flirting with LLBLGen in former company, first I began using as much of typed datasets as possible, and now I'm using Linq to SQL and I'm pretty happy with it. I do not think that using sprocs is wrong or anything like that because, obviously, a lot of good solutions developed with sprocs run just fine.

However, I do have strong feeling that using ORM helps a lot in development and maintenance of applications targeting different databases - just as Mojo Portal. I think so because rewriting sprocs is definitely huge task with little to no automation available...except, maybe and just maybe, very expensive software like ERwin data modeler (I didn't have neither time neither full opportunity to try that supposed sproc translation feature out). The way I see it, sprocs are the biggest portability obstacle in all web apps that use them because, while DB datatypes and SQL query syntax are very similar across different DB platforms (and ORMs handle them anyway), procedure languages are not.

So, wouldn't you, as main MP developer, enjoy gross benefits if using ORM paradigm in further MP development? Wouldn't it greatly reduce workhours needed to maintain a lot of different data layers? What do you see as ORMs main drawback?

Consider attempt to port some sproc-based CMS, be it Mojo Portal, Dot Net Nuke or whatever, to, say, Oracle. Rewriting hundreds of sprocs is daunting task. On the other hand, generating new data layer with some ORM tool, NHibernate, LLBLGen or whatever, is breeze in comparison.

What do you think about it?

12/29/2008 8:08:45 AM
Gravatar
Total Posts 18439

Re: NHibernate to replace SQL code

Hi Slaven,

Believe me, I've had enough flames thrown my way over the last few years over this issue and I have no energy to invest in any more arguments. I choose not to use an OR mapper and that is not going to change. If developers want to use NHibernate in their custom features nothing stops them from that, but I'm not going there any time soon myself.

The ORM crowd often asserts that it solves the multiple database support problem, but really I do not see a lot of projects actually supporting multiple databases well like mojoPortal does. It seems mostly theoretical. Show me any other projects you see that really support 5 databases like I do in mojoPortal.

While its true that any supposed performance benefits of using stored procedures is so small as to be hard to measure, there are security benefits that can be important and should not be dismissed lightly. Its certainly more work supporting stored procs in my experience. Originally I was using procs for pgsql, but now I only continue to use procs for MS SQL.

There are many formal environments out there where the dba will not allow dynamic sql because it makes their job difficult not knowing what rogue sql statements may be hindering performance. Using procs also allows hardening the installation by using a db user with only permission to execute the procs and no direct permissions on any tables. mojoPortal using MS SQL can be used in these environments where OR mappers will not be allowed. I think Oracle shops also tend to have DBAs and tend to be very formal as well, so to me its questionable whether a dynamic sql data layer for Oracle would have appeal in a lot of Oracle shops. I think many of them would rather have procs.

I do not like the way most OR mappers want to be the base class for business objects. This makes it an all or nothing thing you can either use it or not use it. If there was a way to abstract it so that a NHibernate data layer could be implemented like the other data layers as a service tier that would be cool, but its not like that, you would end up with a parrallel set of objects that really want to be the business objects and there is no easy way to get an IDataReader so its impossible to implement the same api with NHibernate as our existing data layers do.

To me, every developer should understand databases and sql, with OR mappers we are headed towards using a lot of wizard generated code that the developers don't really understand. I know sql well and I don't find it to be terribly difficult, its very straightforward.

When there is any problem I find it much easier to debug it when I can get straight to the sql code rather than have some big chunk of middle ware to debug through.

I also think OR mappers tend to have more overhead than I would like. For fast web sites you need to optimise and use IDataReader to get best performance. To me it seems silly to create a List of objects just to databind a dropdown or grid, its a lot of un-needed object creation that adds no value other than making things more object oriented. When you look at things like the PetShop application where MS showed how much faster .NET is than java, they did it by optimising this way. If they had valued pure theoretical OOP over actual performance they would not have beaten java.

Using code generation as a jump start I get very rapid development, so the supposed faster development of using OR mappers is not so big to attract me.

Best,

Joe

 

12/29/2008 11:28:23 AM
Gravatar
Total Posts 18439

Re: NHibernate to replace SQL code

Just as additional information, at one time I got excited about using SubSonic, as it seemed like an OR mapper even I could love because it can return IDataReader and act like a data service rather than a business layer. I even got it working by implementing custom providers for Firebird and pgsql and sqlite using some partial implementations I had found. I started down this path and went a good ways thinking it was going to save me effort but in fact it made things more difficult to debug and therefore less easy to maintain than sql which is very straightforward. I also did some profiling with Ants Profiler and found it was using a lot more resources than my traditional approach, so ultimately I ended up backing out everything I used it for and doing it the way I've been doing it all along. I put quite a bit of effort into pursuing this path before deciding my orignal approach is still better for me. I use code generation for a jump start in any of the data layers but when there is a bug its very easy to solve it. The very fact that I do support 5 databases and continue to advance the progress of the project rapidly pretty much all by myself demonstrates that my approach is very productive.

I think many of these OR mappers can solve the problem of working with any single db platform, but when you generate code against one platform it may not always really work with another platform just by creating tables in the new platform. There are mismatches that can cause troubles like having to use char(36) for databases that don't have a Guid data type, things can get weird when your main database uses mixed case tables and another db like pgsql forces them all lower case. I'm sure the OR mappers try to solve these issues but I'm not convinced they actually do solve them all. These difference can create corner case bugs that are hard to solve. Thats why I ask if you know of other projects using NHibernate and really supporting multiple databases. In practice I'm not sure how well it really lives up to the theory. If I see a complex project really support 5 dbs and not have bugs that only happen in some dbs then I will believe it.  Of course we do get db platform specific bugs in mojoPortal too, but in this case its easy to fix them whereas with NHibernate I would be unable to solve it if it works for some dbs and not others. I would have to report it to the NHibernate project and be at the mercy of whether they can solve it or even care enough to try.

Best,

Joe

8/5/2010 2:33:49 AM
Gravatar
Total Posts 23

Re: NHibernate to replace SQL code

Hi ,

What about EnterpriseLibrary?

i think they are doing nice job ? Also we and alot of people working with ready to use provider models.

So why not ?

8/5/2010 6:14:38 AM
Gravatar
Total Posts 18439

Re: NHibernate to replace SQL code

http://www.mojoportal.com/why-i-dont-use-an-or-mapper-in-mojoportal.aspx

I have been developing mojoPortal since 2004 and I am content with our data access architecture. Changing it would be a lot of work, work is time and time is money. I don't have time to re-write mojoPortal every year when new data access technology comes out. Changing to Enterprise library does not solve any problem that I need to solve. There are many many problems that I am interested in solving but the idea to change all the data access to enterprise library is a solution in search of a problem, it does not address any existing problem for mojoPortal or users of mojoPortal.

If you want to use it in your own custom development then use it.
 

You must sign in to post in the forums. This thread is closed to new posts.