Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need for Hibernate in the legacy world [closed]

I have a several questions about hibernate.

In many questions here in stackoverflow, several people are saying that hibernate is not a good choise for very complex databases. If we have very complex database, hibernate is not the right choice. It better suits for green field projects, but it is not so good for complex legacy database.

  1. Is this true?
    Also hibernate generates queries. Every project manager will like to have optimized queries (hibernate cannot generate more optimized queries than sql specialist!). So for big project it is not a problem to hire sql specialist. The sql specialist will optimize the queries (use explain sql, use joins ...)

  2. My question is how come a huge and expensive project does not care about sql optimization?
    (you will say that you can write HQL but as I have seen in a lot of posts that explains that HQL is not so powerful than sql and a lot of programmers get headache and several hours of tuning) (you like all your organs in your body to work ideally don't you?) Also the second level cache helps hibernate a lot because hibernate knows to generate a lot of queries instead of complex join.

  3. My question is: Is really a complex db only modified by one system (example the web site)? If we are talking about the enterprise system the db can be accessed via several processes, sharing different programming languages and platforms.
    So in this case the second level cache does not help very much.

  4. For what kind of projects hibernate is suitable for? Is it for back office projects where nobody cares about the sql ?

  5. What happens when your administrator says: please use memcached for caching and please use this optimized queries instead of yours?

If you are using oracle database, orache has the most advanced sql syntax. They have spend a lot of time and money on the syntax that is very powerful. What for is this syntax if it is not used.

The software is written only once (and then maintained) and used for a long time. If I am a company that orders software I will say: I will use the software for a couple of years and I like to be fast, and if you spend 1 month for writing software with hibernate I will pay one more month for software that uses example IBATIS knowing that it will work better for years
(when you are buying a car you are interested in the car economy 1kg-oil/km, not how short and easy the manufacturer produced the car!). So as a software consumer I do not interested in your productivity, just how fast the software is. Of course also the price is relevant but if we are speaking about the price there are more complex mathematics.

Can we call something engineering when we really cannot predict some part of the system?
(can electrical engineer be really a engineer if he cannot predict the current)

Please share your opinion.

Regards

like image 773
darpet Avatar asked Jul 16 '10 21:07

darpet


1 Answers

1) (...) Is this true?

No it isn't, Hibernate can deal with pretty complex databases, including existing ones. However, it might not deal very well with an heavily denormalized database or an exotic schema. This is different.

2) (...) My question is how come a huge and expensive project does not care about sql optimization?

This is non-sense, using Hibernate doesn't mean you don't care about optimization. I have worked on a huge and complex STP system (several hundreds millions € budget) and performance was definitely an important concern and we actually introduced Hibernate to benefit from things like lazy loading, second level cache (and speed up development).

Here is the deal when using an ORM like Hibernate (when suitable):

  • You'll be done faster with ORM than without ORM (or there wouldn't be any point at using them).
  • The vast majority of the generated queries will behave correctly (and the fact is that Hibernate generates better SQL than the average developer).
  • You can (and have to) tune queries and Hibernate to a certain degree.
  • Even if you spend some time on performance optimization (including falling back to native SQL for really problematic queries), you'll still be done faster.

3) (...) So in this case the second level cache does not help very much.

Well, you are right about the fact that using the second level cache ideally means using Hibernate APIs (although you can still evict the cache "manually" and although I tend to prefer using it for "mostly read" entities). But, more important, to my experience sharing data between many applications through the database just leads to unmaintainable applications (changing a single bit becomes impossible as it may impact several applications) and and should be avoided. Use an EAI/ESB and expose services of the main system through it. This way, you can reuse the business logic, the 2nd level cache, etc.

4) (...) For what kind of projects hibernate is suitable for? Is it for back office projects where nobody cares about the sql ?

Hibernate is indeed very nice for CRUD applications, but not only (see above) and your question shows some ignorance as I already said. However, it isn't suitable for any project:

  • I would probably not use it for a data warehouse or a big reporting application.
  • I might not use it with a heavily denormalized or exotic legacy database (a data mapper like mybatis might be a better choice in this case).
  • I might not use it with an existing system using stored procedure for everything.
  • I would not use it with a non RDBMS datastore :)

5) (...) What happens when your administrator says: please use memcached for caching and please use this optimized queries instead of yours?

I tell him that memcached is maybe not the best solution in our context (no, I don't want to always send my data over the wire and I don't care that Facebook/LiveJournal/Twitter/whatever are using it, our app might have different needs), there are other better cache implementations when working with Hibernate, I ask him to discuss problems with me and we discuss the various solutions, etc. We work as a team, not against each other.

To sum up, ORM solutions are not always suitable but I think that you currently have a biased opinion and my experience is different from the opinions (misbeliefs?) expressed in your question.

See also

  • When NOT to use O/R mapping in Java
like image 137
Pascal Thivent Avatar answered Oct 27 '22 03:10

Pascal Thivent