1 / 54

Become the nhibernate Guru

Become the nhibernate Guru. Torkel Ödegaard. torkel.odegaard@gmail.com. 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

zan
Download Presentation

Become the nhibernate Guru

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Become the nhibernate Guru

  2. Torkel Ödegaard torkel.odegaard@gmail.com www.codinginstinct.com

  3. Nhibernate? ORM (Object-Relational Mapper) Transparent persistance Persistence ignorance

  4. Become the Guru • Identity map (L1 Cache) • Unit Of Work (Session Flush) • Cascading • Attached / Detached • Proxy / Lazy loading • ID generation / unsaved-value • Concurrency • Legacy databases • Performance

  5. IStarShip

  6. Those WERE the droids I was looking for...

  7. MAPPing

  8. Mapping

  9. example

  10. Session management

  11. unit of work

  12. unit of work session.Flush()

  13. Flush Mode • Auto • Commit • Never • Unspecified

  14. Transaction Unit Of Work

  15. identity map True

  16. identity map True

  17. identity map - Problems Same instance Will return instance from identity map

  18. identity map - Problems NHibernate.NonUniqueObjectException A different object with the same identifier value was already associated with the session Two instances with same id

  19. identity map - Problems NHibernate.HibernateException Identifier of an instance of TieFighter was altered …

  20. Cascading

  21. cascading • None • Save-update • Delete • Delete-orphan • All • All-delete-orphan

  22. Cascade & Save-update Transient (unsaved) instance Transient (unsaved) instance INSERT INTO Pilot .... INSERT INTO TieFighter ...

  23. Cascade & delete DELETE TieFighter ... DELETE Pilot ...

  24. Cascade & none Transient (unsaved) instance Transient (unsaved) instance NHibernate.TransientObjectException Object references an unsaved transient instance -save the transient instance before flushing

  25. Cascade & none

  26. Cascade & none

  27. Cascade & none UPDATE Pilot ...

  28. Attached NHibernate.HibernateException Illegal attempt to associate a collection with two open sessions

  29. Detached INSERT INTO TieFighter ... UPDATE StarDestroyer ... UPDATE TieFigher #1 ... UPDATE TieFigher #2 ... UPDATE TieFigher #3 ... UPDATE TieFigher #4 ... UPDATE TieFigher #5 ... Updating a detached instance

  30. Reassociate Reassociate (attaches) instance to session INSERT INTO TieFighter ...

  31. Merge Modified detached Instance Attached instance with modifications SELECT ... FROM StarDestroyer WHERE ... SELECT ... FROM TieFigher WHERE ... INSERT INTO TieFighter ...

  32. PRoxy

  33. PRoxy

  34. PRoxy

  35. Fetch Select / Lazy /N plus 1

  36. Fetch join

  37. inverse false

  38. concurrency

  39. Concurrency

  40. Concurrency - version

  41. Concurrency - version

  42. Concurrency - timestamp

  43. legacy • Composite primary keys • Relations on non-primary keys • Join • SQL Queries • DB Generated fields

  44. Property-ref

  45. Sql queries

  46. generated - insert

  47. performance • Batching • Eager loading (eliminate N+1) • Query Cache • L2 Cache

More Related