1 / 45

Become the nhibernate Guru

Become the nhibernate Guru. Torkel Ödegaard. www.codinginstinct.com. Nhibernate?. ORM (Object-Relational Mapper). Transparent persistance. Persistence ignorance. The problem?. Become the Guru. Identity map (L1 Cache) Unit Of Work (Session Flush) Cascading Attached / Detached

latif
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 www.codinginstinct.com

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

  4. The problem?

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

  6. Order Customer * * OrderLine Corporate Customer Personal Customer

  7. IStarShip

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

  9. MAPPing

  10. Mapping

  11. example

  12. Session management

  13. unit of work

  14. unit of work session.Flush()

  15. Transaction Unit Of Work

  16. identity map True

  17. identity map True

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

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

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

  21. Cascading

  22. Cascading

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

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

  25. Cascade & delete DELETE TieFighter ... DELETE Pilot ...

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

  27. Cascade & none INSERT TieFighter ...

  28. Cascade & none

  29. Cascade & none UPDATE Pilot ...

  30. Attached / Detached *

  31. Attached / Detached

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

  33. 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

  34. The ideal

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

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

  37. Lazy Loading

  38. PRoxy

  39. Proxy

  40. PRoxy

  41. unsaved-value

  42. Concurrency UPDATE Pilot SET Version = 2 Name = ’Boba Fett’ Ranking = 1 WHERE Id = ’62E96390-DDB4-493A-A216-62B45C86312’ AND Version = 1 NHibernate.StaleObjectException

  43. resources • http://nhforge.org/ • http://ayende.com/blog • http://www.codinginstinct.com • http://sharparchitecture.net/ • http://nhprof.com Torkel.odegaard@gmail.com

More Related