1 / 50

Become the nhibernate Guru

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

royal
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? Identity map (L1 Cache) Unit Of Work (Session Flush) Cascading Attached & Detached Lazy loading & Proxy Objects ID generation & unsaved-value Concurrency

  5. Order Customer * * OrderLine Corporate Customer Personal Customer

  6. IStarShip

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

  8. MAPPing

  9. Mapping

  10. example

  11. unit of work session.Flush()

  12. Transaction Unit Of Work

  13. Session management

  14. Session management

  15. Session management

  16. Session management

  17. identity map True

  18. identity map True

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

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

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

  22. Cascading

  23. Cascading

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

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

  26. Cascade & delete DELETE TieFighter ... DELETE Pilot ...

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

  28. Cascade & none INSERT TieFighter ...

  29. Cascade & none

  30. Cascade & none UPDATE Pilot ...

  31. Why???? I did set cascade = none

  32. Cascade & none UPDATE Pilot ...

  33. Attached / Detached

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

  35. Detached *

  36. Attached / Detached

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

  38. The ideal

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

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

  41. Lazy Loading

  42. PRoxy

  43. Proxy

  44. PRoxy

  45. unsaved-value

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

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

More Related