Why Do I Hate Hibernate?


Published on

Presentation from "Anonymous Developers Club" gathering in Kiev on "ORM" topic

Published in: Technology
  • I agree and I'd like to add two other issues. The first one is that Hibernate generates Proxy Classes that consumes lots of memory (-XX:MaxPermSize) on large projects crashing the server: its fine for 'Hello World'. The second one is that Lazy strategy is useless for service oriented projects like a Rest API because serialization causes all getters to be invoked.
    Are you sure you want to  Yes  No
    Your message goes here
  • Many people are completely unaware of possibility of deadlocks in database and are unaware about the fact, that hibernate don't offer instruments to control locking order. We struggled this problem in production and found no solution other than doing explicit Session.flush to ensure query ordering. That a shame.
    Are you sure you want to  Yes  No
    Your message goes here
  • It turns out, that grandma is smarter than many of today's programmers. I also didn't know about slide #7. Thanks you, Mikalai, cool speech, especially in the end of conference!
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Why Do I Hate Hibernate?

  1. 1. Why Do I Hate Hibernate?<br />Mikalai Alimenkou<br />http://xpinjection.com<br />13.09.2011<br />
  2. 2. Nobody understand how equals and hashCode must look like <br /><ul><li> There is no common solution
  3. 3. It is hard decision when there is no “unique business key” for the entity
  4. 4. Many issues with inclusion of child collections in calculation</li></li></ul><li>Mutable objects are evil <br /><ul><li> Default constructor must present
  5. 5. Fields can’t be final
  6. 6. State of object may become inconsistent
  7. 7. Or… reflection magic will happen</li></li></ul><li>DTO is evil pattern with Hibernate<br /><ul><li> Lots of code duplication
  8. 8. Hard to maintain if many entities exists
  9. 9. No simple and common pattern implementation
  10. 10. Silent DTO mapping errors
  11. 11. With large object tree it is like hell</li></li></ul><li>Criteria API or HQL? <br /><ul><li> Some simple things are missed in Criteria API (for example, filtering by collection of elements)
  12. 12. Mixing HQL and Criteria API looks strange
  13. 13. Criteria API is designed for dynamic queries, but not HQL</li></li></ul><li>To update single field you should read full entity<br /><ul><li> Child collections retrieved as well or made lazy
  14. 14. Few people understand in details how lazy loading works
  15. 15. At least 2 SQL queries to update single field
  16. 16. This pattern makes developers stupid</li></li></ul><li>Parent records are copied to temporary table on update or delete<br />
  17. 17. Entity state can be managed only from one side in parent-child relationship<br />
  18. 18. Flush on commit is too unpredictable<br /><ul><li> Entity can’t be changed to avoid DB update
  19. 19. Child collections must be copied before modification
  20. 20. Constraint exception handling code may be missed at all
  21. 21. No control of queries ordering that may cause deadlocks</li></li></ul><li>Documentation is simple but primitive<br /><ul><li> Only basic samples are covered
  22. 22. For all complex things you need to consult with books (“Java Persistence with Hibernate” is the best)
  23. 23. Bug reports are ignored by development team</li></li></ul><li>Hibernate makes developers stupid<br /><ul><li> Many of them don’t know JDBC at all
  24. 24. Few people go deeper than simple mapping
  25. 25. Almost nobody count number of SQL queries performed and their structure
  26. 26. Very few people know how to tune Hibernate via JDBC parameters</li></li></ul><li>Any questions?<br />