Sunday, December 9, 2007

Is Hibernate Portable?

Hibernate is considered to be portable framework in which you can move from one databse to another database without the need to change the code at all, Does is it true?

It is true that most of the code and the HBM files (or anotations) would remain the same when moving from one database to another database, however there are some exceptional cases.

For example consider the following simple HQL query:
select from USERS where NAME=?

If the column NAME is nullable in the databse and you would pass null value as parameter then in MySQL it would return all the rows where NAME is NULL, However in Oracle it wouldn't return any row at all, the reason for it is that in Oracle
NULL==NULL is false.

There are other much more exceptional cases, please comment if you need other examples.

So the answer for the question is Hibernate Portable is Yes for 90% of code but No for 10% other perecent of code.


djo.mos said...

Well ... I guess one should say 99% portable when seeing the cases where it is not so ... I mean, who the heck is going to compare a column with null ? ;-)
Also, if null!=null, I consider that a bug in the DB and not a non-portable issue with Hibernate, don't you ?

Illya Kysil said...

2djo.mos: read SQL 92 standard, subclause 8.2 - you will find many interesting things...

Danail Nachev said...

Shouldn't Hibernate handle cases like this? Otherwise, it isn't very portable indeed?

willCode4Beer said...

It is probably one of the most portable ORM libraries around. I've used it to switch between Oracle (production) and HSQL (demo cd's) with great success. But, my case is definitely an exception. Really, how many people make live-cd's of web applications?

Database portability is often overrated. There are very very few cases where an application needs to be able to run on more than one database. There is often a great deal of logic outside of the app with the ORM requirement.

When is the last time you swapped your RDMS?

Fabian said...

Actually we do. We support our software for Oracle and Postgres. Hibernate helps a lot in our case but we ran into some issues - it was easy to work around them though.
There are far too many differences between DBMSs for Hibernate for fix them automatically. It'd be boring otherwise ;)

Ignacio Coloma said...

I can only suppose that your case should work using QBE or Criteria objects, but not with HQL or EQL (which I suppose is your case)


RSS Feeds Submission Directory