Why I am not a fan of Hibernate

  1. Rich Domain Model + Lazy-loading cause problems
    1. Hiberntate encourages rich domain model over table model, that is,  A.b instead of A.bId
    2. You must enable lazy-loading, otherwise there will be performance issues
    3. If you are not in a hibernate session, A.b will be invalid ("Partial Materialization" problem)
    4. To make user you are in a hibernate session, you will use OpenSessionInView pattern
    5. But OpenSessionInView is an ANTI-PATTERN.  Your code will not work in non-web applications or in Unit tests . Yes, there are workarounds, but why bother with Hibernate? 
    6. With table model, all these problems go away, albeit the price of writing SQL manually.
  2. Hibernate has a high learning curve, but your teammate just finished the first 3 chapters
    1. They may not have solid understanding of object states (transient, persistent, detached), which requires great care. The result is you see hibernate exceptions from time to time. 
    2. They don’t know about Partial Materialization problem mentioned above 
    3. Believe me, it happens. You may have junior members in your team, or some mates who are just too confident to take Hibernate as a heavy tool.
    4. With table model, all these problems go away. You will have a more robust system and will allow the team to recruit fresh graduates.  
  3. You lose control over low-level DB manipulation.  This is not a problem if your system is a low-scale one. 

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.