SlideShare uma empresa Scribd logo
1 de 19
1.E’ un algoritmo ricorsivo: Tutti le istanze di 
oggetti “raggiungibili” da un oggetto 
persistente diventano anch’essi persistenti. 
Top Level 
(root)
Transient 
Entity 
Persistent 
Entity 
Detached 
Entity 
Persistence Context
Soluzione di NHibernate: 
Persistence by Reachability con Cascade 
Istanza Istanza 
Associazione 
Cascade 
Behaviour
• Hibernate Query 
Language 
• Linguaggio di 
Intgerrogazione 
Object Oriented 
• Interrogazione 
mediante SQL puro 
• Risultato mappato 
sulle entity 
• Query by example 
• Query prodotta a 
partire da una 
istanza di oggetto 
prorotipo 
• Query By Criteria 
• Esecuzione di 
Query Type Safe e 
Object Oriented 
QbC QbE 
HQL 
SQL 
native
Immediate Fetching 
Lazy Fetching 
Eager Fetching
lazy eager
User Interface Layer 
Context E E E 
Business Layer 
Context E E 
Data Access Layer 
Context Provider 
DAO DAO DAO 
Context: 
Identity Map 
Unit of Work 
Automatic Dirty Check 
Optimistic Concurrency 
Pessimistic Concurrency 
Proxy per Lazy...
application application 
session 
(cache 1° level) 
cache distribuita 
(2° level) 
session 
(cache 1° level) 
application 
session 
(cache 1° level) 
cache 
(2° level) 
application 
session 
(cache 1° level)
“...Hibernate’s job is to reduce the amount of code you have to write 
for the most common 90 percent of use cases (common CRUD and 
reporting)...” 
“…Hibernate’s learning curve is high at first. 
In our experience, a developer needs at least two to four weeks to 
learn the basics. 
Don’t jump on Hibernate one week before your project deadline. 
It won’t save you…” 
“…Finally, use SQL, JDBC, and stored procedures for the 5 percent of 
use cases 
you can’t implement with Hibernate, such as mass data manipulation 
or complex reporting queries with vendor-specific SQL functions…” 
[Gavin King, Hibernate in Action]
Il Domain Model agnostico al layer di persistenza...ma deve essere 
disegnato per “favorire” la persistenza... 
Fornire Identity Field a tutte gli Entity Type 
Entity che hanno delle collection devono essere definite come 
IList<T> (favorisce la Dependency Injection) 
Evitare classi sealed per le entity che hanno bisogno di lazy (gli 
ORM solitamente forniscono dei proxy object) 
DB: Favorite l’uso Surrogate Keys in luogo di Natural Keys, evitate 
Composite Keys, pensate al Versioning

Mais conteúdo relacionado

Semelhante a NHibernate in Action (Parte 2)

Smau milano 2012 massimiliano del cero
Smau milano 2012 massimiliano del ceroSmau milano 2012 massimiliano del cero
Smau milano 2012 massimiliano del ceroSMAU
 
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDBPolyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDBSteve Maraspin
 
Netbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHPNetbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHPGiorgio Cefaro
 
Microsoft Azure per l'IT Pro
Microsoft Azure per l'IT ProMicrosoft Azure per l'IT Pro
Microsoft Azure per l'IT ProMarco Parenzan
 
Repository pattern slides v1.1
Repository pattern slides v1.1Repository pattern slides v1.1
Repository pattern slides v1.1Christian Nastasi
 
Azure for Game Developers
Azure for Game DevelopersAzure for Game Developers
Azure for Game DevelopersMarco Parenzan
 
Oracle Application Server 10g
Oracle Application Server 10gOracle Application Server 10g
Oracle Application Server 10gPaolo Campegiani
 
Azure dayroma java, il lato oscuro del cloud
Azure dayroma   java, il lato oscuro del cloudAzure dayroma   java, il lato oscuro del cloud
Azure dayroma java, il lato oscuro del cloudRiccardo Zamana
 
Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...
Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...
Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...azuredayit
 
festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...
festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...
festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...festival ICT 2016
 
Androidsdk appinventor
Androidsdk appinventorAndroidsdk appinventor
Androidsdk appinventorfdizazzo
 
Node.js - Server Side Javascript
Node.js - Server Side JavascriptNode.js - Server Side Javascript
Node.js - Server Side JavascriptMatteo Napolitano
 
Twcrashcourse
TwcrashcourseTwcrashcourse
Twcrashcourserik0
 
Writing apps for android with .net
Writing apps for android with .net Writing apps for android with .net
Writing apps for android with .net Leonardo Alario
 

Semelhante a NHibernate in Action (Parte 2) (20)

Il web 2.0
Il web 2.0Il web 2.0
Il web 2.0
 
Smau milano 2012 massimiliano del cero
Smau milano 2012 massimiliano del ceroSmau milano 2012 massimiliano del cero
Smau milano 2012 massimiliano del cero
 
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDBPolyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
Polyglot Persistance con PostgreSQL, CouchDB, MongoDB, Redis e OrientDB
 
Web frameworks
Web frameworksWeb frameworks
Web frameworks
 
Netbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHPNetbeans e Xdebug per debugging e profiling di applicazioni PHP
Netbeans e Xdebug per debugging e profiling di applicazioni PHP
 
Repository pattern
Repository patternRepository pattern
Repository pattern
 
Microsoft Azure per l'IT Pro
Microsoft Azure per l'IT ProMicrosoft Azure per l'IT Pro
Microsoft Azure per l'IT Pro
 
Repository pattern slides v1.1
Repository pattern slides v1.1Repository pattern slides v1.1
Repository pattern slides v1.1
 
Azure for Game Developers
Azure for Game DevelopersAzure for Game Developers
Azure for Game Developers
 
Oracle Application Server 10g
Oracle Application Server 10gOracle Application Server 10g
Oracle Application Server 10g
 
Azure dayroma java, il lato oscuro del cloud
Azure dayroma   java, il lato oscuro del cloudAzure dayroma   java, il lato oscuro del cloud
Azure dayroma java, il lato oscuro del cloud
 
Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...
Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...
Azure Day Rome 2019 Reloaded - Utilizzare Azure Kubernetes Service per i nost...
 
SCBCD 1. generic ejb
SCBCD 1. generic ejbSCBCD 1. generic ejb
SCBCD 1. generic ejb
 
festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...
festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...
festival ICT 2013: Gestire criticità in maniera efficiente per liberare slot ...
 
Androidsdk appinventor
Androidsdk appinventorAndroidsdk appinventor
Androidsdk appinventor
 
Fmdp Total System Monitor
Fmdp Total System MonitorFmdp Total System Monitor
Fmdp Total System Monitor
 
Node.js - Server Side Javascript
Node.js - Server Side JavascriptNode.js - Server Side Javascript
Node.js - Server Side Javascript
 
App Engine + Python
App Engine + PythonApp Engine + Python
App Engine + Python
 
Twcrashcourse
TwcrashcourseTwcrashcourse
Twcrashcourse
 
Writing apps for android with .net
Writing apps for android with .net Writing apps for android with .net
Writing apps for android with .net
 

Mais de DotNetMarche

Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...DotNetMarche
 
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...DotNetMarche
 
UI Composition - Prism
UI Composition - PrismUI Composition - Prism
UI Composition - PrismDotNetMarche
 
Model-View-ViewModel
Model-View-ViewModelModel-View-ViewModel
Model-View-ViewModelDotNetMarche
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyondDotNetMarche
 
Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)DotNetMarche
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in ActionDotNetMarche
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in ActionDotNetMarche
 
Soluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-LearningSoluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-LearningDotNetMarche
 
Installing and Administering MOSS
Installing and Administering MOSSInstalling and Administering MOSS
Installing and Administering MOSSDotNetMarche
 
Microsoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical OverviewMicrosoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical OverviewDotNetMarche
 
[Hands on] testing asp.net mvc
[Hands on] testing asp.net mvc[Hands on] testing asp.net mvc
[Hands on] testing asp.net mvcDotNetMarche
 
Asp.NET MVC Framework
Asp.NET MVC FrameworkAsp.NET MVC Framework
Asp.NET MVC FrameworkDotNetMarche
 
Introduzione al Testing
Introduzione al TestingIntroduzione al Testing
Introduzione al TestingDotNetMarche
 
Introduzione a CardSpace
Introduzione a CardSpaceIntroduzione a CardSpace
Introduzione a CardSpaceDotNetMarche
 

Mais de DotNetMarche (20)

Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...Creare una community dal basso ed arrivare ad un'azienda milionaria  - Emanue...
Creare una community dal basso ed arrivare ad un'azienda milionaria - Emanue...
 
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
Metriche per Zombie Communities: come "iniettare vita" in tribù di morti vive...
 
WPF 4 fun
WPF 4 funWPF 4 fun
WPF 4 fun
 
UI Composition - Prism
UI Composition - PrismUI Composition - Prism
UI Composition - Prism
 
UI Composition
UI CompositionUI Composition
UI Composition
 
Model-View-ViewModel
Model-View-ViewModelModel-View-ViewModel
Model-View-ViewModel
 
WPF basics
WPF basicsWPF basics
WPF basics
 
Refactoring ASP.NET and beyond
Refactoring ASP.NET and beyondRefactoring ASP.NET and beyond
Refactoring ASP.NET and beyond
 
Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)Refactoring 2TheMax (con ReSharper)
Refactoring 2TheMax (con ReSharper)
 
jQuery Loves You
jQuery Loves YoujQuery Loves You
jQuery Loves You
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in Action
 
Silverlight in Action
Silverlight in ActionSilverlight in Action
Silverlight in Action
 
Open XML & MOSS
Open XML & MOSSOpen XML & MOSS
Open XML & MOSS
 
Soluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-LearningSoluzioni Microsoft per l'e-Learning
Soluzioni Microsoft per l'e-Learning
 
Installing and Administering MOSS
Installing and Administering MOSSInstalling and Administering MOSS
Installing and Administering MOSS
 
Microsoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical OverviewMicrosoft SharePoint Server 2007 Technical Overview
Microsoft SharePoint Server 2007 Technical Overview
 
[Hands on] testing asp.net mvc
[Hands on] testing asp.net mvc[Hands on] testing asp.net mvc
[Hands on] testing asp.net mvc
 
Asp.NET MVC Framework
Asp.NET MVC FrameworkAsp.NET MVC Framework
Asp.NET MVC Framework
 
Introduzione al Testing
Introduzione al TestingIntroduzione al Testing
Introduzione al Testing
 
Introduzione a CardSpace
Introduzione a CardSpaceIntroduzione a CardSpace
Introduzione a CardSpace
 

NHibernate in Action (Parte 2)

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. 1.E’ un algoritmo ricorsivo: Tutti le istanze di oggetti “raggiungibili” da un oggetto persistente diventano anch’essi persistenti. Top Level (root)
  • 8. Transient Entity Persistent Entity Detached Entity Persistence Context
  • 9. Soluzione di NHibernate: Persistence by Reachability con Cascade Istanza Istanza Associazione Cascade Behaviour
  • 10. • Hibernate Query Language • Linguaggio di Intgerrogazione Object Oriented • Interrogazione mediante SQL puro • Risultato mappato sulle entity • Query by example • Query prodotta a partire da una istanza di oggetto prorotipo • Query By Criteria • Esecuzione di Query Type Safe e Object Oriented QbC QbE HQL SQL native
  • 11. Immediate Fetching Lazy Fetching Eager Fetching
  • 12.
  • 13.
  • 14.
  • 16. User Interface Layer Context E E E Business Layer Context E E Data Access Layer Context Provider DAO DAO DAO Context: Identity Map Unit of Work Automatic Dirty Check Optimistic Concurrency Pessimistic Concurrency Proxy per Lazy...
  • 17. application application session (cache 1° level) cache distribuita (2° level) session (cache 1° level) application session (cache 1° level) cache (2° level) application session (cache 1° level)
  • 18. “...Hibernate’s job is to reduce the amount of code you have to write for the most common 90 percent of use cases (common CRUD and reporting)...” “…Hibernate’s learning curve is high at first. In our experience, a developer needs at least two to four weeks to learn the basics. Don’t jump on Hibernate one week before your project deadline. It won’t save you…” “…Finally, use SQL, JDBC, and stored procedures for the 5 percent of use cases you can’t implement with Hibernate, such as mass data manipulation or complex reporting queries with vendor-specific SQL functions…” [Gavin King, Hibernate in Action]
  • 19. Il Domain Model agnostico al layer di persistenza...ma deve essere disegnato per “favorire” la persistenza... Fornire Identity Field a tutte gli Entity Type Entity che hanno delle collection devono essere definite come IList<T> (favorisce la Dependency Injection) Evitare classi sealed per le entity che hanno bisogno di lazy (gli ORM solitamente forniscono dei proxy object) DB: Favorite l’uso Surrogate Keys in luogo di Natural Keys, evitate Composite Keys, pensate al Versioning