PERSISTING RICH DOMAIN MODELS USING NHIBERNATE
IStarShip
• Intro• Unit Of Work• Identity Map• Demos• Basics• cascade & inverse• querying
• Many-to-many• Legacy databases• Performance
Agenda
• Origins in Java (Hiberante 2001)• First release 2004• Last release 2.1.2 (Nov 2009)• Upcoming 3.0 release (Summer 2010)
• http://nhforge.org/
NHibernate
Transparent persistance
MAPPing
Mapping
ISession ISessionFactory
IQuery & ICriteriaITransaction
ISession
Identity Map/L1 Cache
Unit of Work
maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
DEMo
idgenerators
increment
identity
sequence
hiloseqhilo
uuid.hexuuid.string
guid
guid.comb
assignednative
foreign
id generator - identity
id generator - hilo
id generator - hilo
PRoxy
PRoxy
PRoxy
Fetch Select / Lazy / N plus 1
Fetch join
inverse false
• none• save-update• delete• delete-orphan• all• all-delete-orphan
Cascade
value objects
Components
Components
Components
• table per class hierarchy• table per subclass• table per concrete class
inheritance
Model
Table PER CLass
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