become the nhibernate guru
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 PresentationTRANSCRIPT
Become the nhibernate Guru
Nhibernate?ORM (Object-Relational Mapper)
Transparent persistance
Persistence ignorance
• 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
IStarShip
Those WERE the droids I was looking for...
MAPPing
Mapping
example
session
Session
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()
• Auto
• Commit
• Never
• Unspecified
Flush Mode
Transaction
Unit Of Work
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.
identity map
True
identity map
True
identity map - Problems
Same instance
Will return instance from identity map
identity map - Problems
Two instances with same id
NHibernate.NonUniqueObjectException A different object with the same identifier value was already associated with the session
identity map - Problems
NHibernate.HibernateExceptionIdentifier of an instance of TieFighter was altered …
Cascading
cascading
• None• Save-update• Delete• Delete-orphan• All• All-delete-orphan
Cascade & Save-update
Transient (unsaved) instance
Transient (unsaved) instance
INSERT INTO Pilot ....INSERT INTO TieFighter ...
Cascade & delete
DELETE TieFighter ...DELETE Pilot ...
Cascade & none
Transient (unsaved) instance
Transient (unsaved) instance
NHibernate.TransientObjectException Object references an unsaved transient instance -save the transient instance before flushing
Cascade & none
Cascade & none
Cascade & none
UPDATE Pilot ....
PRoxy
PRoxy
PRoxy
Fetch Select / Lazy / N plus 1
Fetch join
inverse false
concurrency
Concurrency
Concurrency - version
Concurrency - version
Concurrency - timestamp
• Composite primary keys
• Relations on non-primary keys
• Join
• SQL Queries
• DB Generated fields
legacy
Property-ref
Sql queries
generated - insert
• Batching
• Eager loading (eliminate N+1)
• Query Cache
• L2 Cache
performance
Batching
Batching
NHibernate = endless number of features
i could go on an on...
• http://nhforge.org/
• http://ayende.com/blog
• http://www.codinginstinct.com
• http://sharparchitecture.net/
resources
http://tlo.googlecode.com/svn/trunk/presentations/nhibernate_elevate