1 of 56

Seriously.�Why Hibernate?

Java User Group

(Silesia)

2 of 56

Hypothesis

Hibernate is always suboptimal solution

3 of 56

but before ...

4 of 56

5 of 56

SQL

6 of 56

JDBC + SQL

7 of 56

Experiment

Hibernate vs JdbcTemplate

8 of 56

Hibernate

Myths

  • No need to worry about SQL
  • DRY communication
  • Easy relation management
  • Easy query refactoring
  • No boilerplate
  • Type-safety
  • Easy migrations
  • Unification between databases
  • Easy scale
  • Easy cache
  • Easy multi-tenant

9 of 56

JDBC Template + SQL

10 of 56

JDBC Template + SQL

11 of 56

JDBC Template + SQL

12 of 56

JDBC Template + SQL

13 of 56

JDBC Template + SQL

14 of 56

15 of 56

Hibernate

16 of 56

Idiomatic persistence

17 of 56

Idiomatic persistence

18 of 56

Idiomatic persistence

19 of 56

Portability

20 of 56

Portability²

21 of 56

EntityManager vs SessionFactory

22 of 56

EntityManager vs SessionFactory

23 of 56

Gotchas

24 of 56

I recommend watching full video: https://www.youtube.com/watch?v=UPWkpl5PL_w

25 of 56

26 of 56

I recommend watching full video: https://www.youtube.com/watch?v=UPWkpl5PL_w

27 of 56

I recommend watching full video: https://www.youtube.com/watch?v=UPWkpl5PL_w

28 of 56

  • FlywayDB?
  • Migration files

29 of 56

  • 3 levels of cache

30 of 56

  • Concurrency
  • Scaling*

31 of 56

32 of 56

33 of 56

34 of 56

35 of 56

Effort

SQL

Mappings and object abstractions

SQL

Boilerplate

SQL

Boilerplate

Hibernate

Plain JDBC

JDBC�Template

36 of 56

37 of 56

Warning! Extra complex, we have TWO tables here! Only DBA experts please!

38 of 56

39 of 56

Mapping

40 of 56

Xml Mapping

41 of 56

Vanilla Hibernate

  • Entity definition

42 of 56

43 of 56

jOOQ

44 of 56

jOOQ

no entity definition

no additional mapping def.

typesafe

no weird indexation

45 of 56

Stored procedures [JDBC]

46 of 56

Stored procedures [JPA]

47 of 56

jOOQ

48 of 56

Recap

49 of 56

Hibernate

Myths

  • No need to worry about SQL
  • DRY communication
  • Easy relation management
  • Easy query refactoring
  • No boilerplate
  • Type-safety
  • Easy migrations
  • Unification between databases
  • Easy scale*
  • Easy cache
  • Easy multi-tenant

50 of 56

Hibernate

Cons

  • HDD ;), Hibernate Driven Development,
  • One way ticket and long term suffering,
  • Bad SQL abstraction,
  • Multi SQL abstraction (Native query, HQL, detached criteria …)
  • Useless features (stamping, versioning, locking),
  • Generated schema = bad design,
  • 3 schemas
  • Gotchas! (ex. HQL LIMIT)

51 of 56

Hibernate

Why?

  • Social proof
  • No reference
  • Never used anything else
  • Don’t know
  • Are there other solutions?
  • Why bother?
  • Naah...

52 of 56

“An expert is a person who avoids small error as he sweeps on to the grand fallacy”

- Benjamin Stolberg

53 of 56

Survey

<External/>

54 of 56

Hibernate

Pros

* I really tried hard to find ones (:

  • any ideas?

55 of 56

Q/A

56 of 56

Thanks!