18.04.2014 mikalai alimenkou · at least 2 sql queries for simple update not everybody understand...

32
Why do I hate Hibernate? Mikalai Alimenkou http://xpinjection.com 18.04.2014

Upload: others

Post on 24-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Why do I hate Hibernate?

Mikalai Alimenkou

http://xpinjection.com

18.04.2014

Page 2: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

9 YEARS,TECH LEAD

7 YEARS,EXPERT

ORGANIZER AND SPEAKER:

FOUNDER AND COACH:

Page 3: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

CRUD*R – read by ID

Page 4: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Why Hibernate is so popular?

1. EJB 2 sucks!

2. New “standard”

+

Page 5: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #1. Nobody understand how equals and hashCode must look like

Page 6: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Hard to select real “unique business key”

Performance issues with collections

Comparison context is very important

Auto-generated fields in Set

Page 7: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #2. Mutable objects are evil

Page 8: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Inconsistent object state is possible

Or… reflection magic happens

Default constructor must

presentFields can’t be final

Page 9: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

POJO bullshit game

Page 10: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #3. DTO is evil pattern with Hibernate

Page 11: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Many solutions: - transformers

- beanutils - reflection- libraries

Crazy DTO “don’t forget” checklist

DTO maintenance is nightmare

Lots of code duplications

Page 12: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #4. LazyInitializationException

Page 13: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Nightmare for newcomers

Almost nobody understand how

it works

Everything is stupidly slow without it

Persistent collections are not serializable

Page 14: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #5. Criteria API or HQL?

=

Page 15: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF?!?No need to know

SQL??? Bullshit!!!

Page 16: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

No check for NULL in HQL

Criteria API only for READ

Different features set in HQL and Criteria API

Hand made query builders in HQL

Page 17: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #6. To update single field you should read full entity

Page 18: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

At least 2 SQL queries for

simple update

Not everybody understand how

‘lazy loading’ works

Children and large fields are loaded

HQL update is not object-oriented

Page 19: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #7. Temporary table usage on update or delete

Page 20: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #8. Composite key requires separate class

Page 21: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #9. Entity state can be managed only from one side in parent-child relationship

Page 22: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #10. Flush on commit is too unpredictable

Page 23: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

No control for SQL queries order

Collections operations are ‘live’

Entity changes are persisted

Constraints are checked on commit

Page 24: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #11. Dirty entity after transaction rollback can’t be reused

Page 25: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #12. Documentation is simple but primitive

Page 26: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Bug reports are ignored

Debug hell to understand how

things work

Only basic samples are coveredFor complex

things you need books

Page 27: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

WTF #13. Hibernate makes developers stupid

Are you joking???

Page 28: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Developers don’t tune JDBC properties

People don’t learn JDBC and SQL

Nobody count SQL queries and care about their

structure

Page 29: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

When we really need to use ORM?

Page 30: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Is CQRS more actual now?

Page 31: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

Useful books

Page 32: 18.04.2014 Mikalai Alimenkou · At least 2 SQL queries for simple update Not everybody understand how ‘lazy loading’ works Children and large fields are loaded HQL update is not

@xpinjectionhttp://xpinjection.com

[email protected]