become the nhibernate guru

51
Become the nhibernate Guru

Upload: cassandra-wooten

Post on 30-Dec-2015

36 views

Category:

Documents


0 download

DESCRIPTION

Become the nhibernate Guru. Torkel Ödegaard. [email protected]. www.codinginstinct.com. Nhibernate?. ORM (Object-Relational Mapper). Transparent persistance. Persistence ignorance. Become the Guru. Identity map (L1 Cache) Unit Of Work (Session Flush) Cascading - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Become the nhibernate Guru

Become the nhibernate Guru

Page 2: Become the nhibernate Guru

Torkel Ödegaard

[email protected]

www.codinginstinct.com

Page 3: Become the nhibernate Guru

Nhibernate?ORM (Object-Relational Mapper)

Transparent persistance

Persistence ignorance

Page 4: Become the nhibernate Guru

• Identity map (L1 Cache)

• Unit Of Work (Session Flush)

• Cascading

• Attached / Detached

• Proxy / Lazy loading

• ID generation / unsaved-value

• Concurrency

• Legacy databases

• Performance

Become the Guru

Page 5: Become the nhibernate Guru
Page 6: Become the nhibernate Guru

IStarShip

Page 7: Become the nhibernate Guru

Those WERE the droids I was looking for...

Page 8: Become the nhibernate Guru
Page 9: Become the nhibernate Guru

MAPPing

Page 10: Become the nhibernate Guru

Mapping

Page 11: Become the nhibernate Guru

example

Page 12: Become the nhibernate Guru

session

Page 13: Become the nhibernate Guru

Session

Page 14: Become the nhibernate Guru

unit of work

Insert entity #1

Insert entity #2

Update entity #3

Delete collection entity #5

Update collection entity #6

Delete entity #8

session.Flush()

Page 15: Become the nhibernate Guru

• Auto

• Commit

• Never

• Unspecified

Flush Mode

Page 16: Become the nhibernate Guru

Transaction

Unit Of Work

Page 17: Become the nhibernate Guru

identity map

An identity map is a database access design pattern 

used to improve performance by providing a context-specific

in-memory cache to prevent duplicate retrieval of the same

object data from the database.

Page 18: Become the nhibernate Guru

identity map

True

Page 19: Become the nhibernate Guru

identity map

True

Page 20: Become the nhibernate Guru

identity map - Problems

Same instance

Will return instance from identity map

Page 21: Become the nhibernate Guru

identity map - Problems

Two instances with same id

NHibernate.NonUniqueObjectException A different object with the same identifier value was already associated with the session

Page 22: Become the nhibernate Guru

identity map - Problems

NHibernate.HibernateExceptionIdentifier of an instance of TieFighter was altered …

Page 23: Become the nhibernate Guru

Cascading

Page 24: Become the nhibernate Guru

cascading

• None• Save-update• Delete• Delete-orphan• All• All-delete-orphan

Page 25: Become the nhibernate Guru

Cascade & Save-update

Transient (unsaved) instance

Transient (unsaved) instance

INSERT INTO Pilot ....INSERT INTO TieFighter ...

Page 26: Become the nhibernate Guru

Cascade & delete

DELETE TieFighter ...DELETE Pilot ...

Page 27: Become the nhibernate Guru

Cascade & none

Transient (unsaved) instance

Transient (unsaved) instance

NHibernate.TransientObjectException Object references an unsaved transient instance -save the transient instance before flushing

Page 28: Become the nhibernate Guru

Cascade & none

Page 29: Become the nhibernate Guru

Cascade & none

Page 30: Become the nhibernate Guru

Cascade & none

UPDATE Pilot ....

Page 31: Become the nhibernate Guru

PRoxy

Page 32: Become the nhibernate Guru

PRoxy

Page 33: Become the nhibernate Guru

PRoxy

Page 34: Become the nhibernate Guru

Fetch Select / Lazy / N plus 1

Page 35: Become the nhibernate Guru

Fetch join

Page 36: Become the nhibernate Guru

inverse false

Page 37: Become the nhibernate Guru

concurrency

Page 38: Become the nhibernate Guru

Concurrency

Page 39: Become the nhibernate Guru

Concurrency - version

Page 40: Become the nhibernate Guru

Concurrency - version

Page 41: Become the nhibernate Guru

Concurrency - timestamp

Page 42: Become the nhibernate Guru

• Composite primary keys

• Relations on non-primary keys

• Join

• SQL Queries

• DB Generated fields

legacy

Page 43: Become the nhibernate Guru
Page 44: Become the nhibernate Guru

Property-ref

Page 45: Become the nhibernate Guru

Sql queries

Page 46: Become the nhibernate Guru

generated - insert

Page 47: Become the nhibernate Guru

• Batching

• Eager loading (eliminate N+1)

• Query Cache

• L2 Cache

performance

Page 48: Become the nhibernate Guru

Batching

Page 49: Become the nhibernate Guru

Batching

Page 50: Become the nhibernate Guru

NHibernate = endless number of features

i could go on an on...

Page 51: Become the nhibernate Guru

• http://nhforge.org/

• http://ayende.com/blog

• http://www.codinginstinct.com

• http://sharparchitecture.net/

resources

[email protected]

http://tlo.googlecode.com/svn/trunk/presentations/nhibernate_elevate