SlideShare a Scribd company logo
Samnang Chhun (samnang@wowkhmer.com)
Software Engineer,
http://tech.wowkhmer.com
Introduction to Object-Relational Mapping
Introduction to NHibernate
NHibernate Basics
Mapping Inheritance hierarchies
Advanced Querying
Additional Reading




                                            2
3
Object-relational mapping (aka ORM, O/RM, and O/R
mapping) is a programming technique for converting data
between incompatible type systems in relational databases
and object-oriented programming languages (Wikipedia)
   Objects are hierarchical
   Databases are relational


                        ORM

     Objects                                Relational




                                                            4
Performance or Scalability
Productivity: less code to write/maintain
Abstraction: transient to different DB technologies
Simplification and Consistency
Quality: depending on the product




                                                      5
ADO.NET Entity Framework (released with .NET 3.5 SP1)
Business Logic Toolkit for .NET
Castle ActiveRecord
IBatis.Net
LightSpeed
Linq (Language Integrated Query)
LLBLGen
LLBLGen Pro
NHibernate
Neo …etc



                                                        6
7
Initially developed for Java
    created in late 2001 by Gavin King
    absorbed by the JBoss Group / Red Hat
Ported to .NET 1.1, 2.0, 3.5
    Resulting product called “NHibernate”
All popular databases supported
    Oracle, SQL Server, DB2, SQLite, PostgreSQL,
    MySQL, Sybase, Firebird, …
XML-based configuration files
Good community support
Free/open source - NHibernate is licensed under the
LGPL (Lesser GNU Public License)

                                                      8
RDBMS

        9
ISessionFactory
   One per database (or application)
   Expensive to create
      Reads configuration
ISession
   Portal to the database
   Saves, retrieves
ITransaction
   Encapsulates database transactions


  SessionFactory
                   Session
                               Transaction
                                             10
11
12
<class> declare a persistent class
<id> defines the mapping from that property to the
primary key column
    Specifies strategy
<property> declares a persistent property of the class
<component> maps properties of a child object to
columns of the table of a parent class.
Associations
    One-to-Many
    Many-to-One
    Many-to-Many
    One-to-One (uncommon)

                                                         13
Element   Description                  .NET Type
<set>     An unordered collection      Iesi.Collections.ISet
          that does not allow          Iesi.Collections.Generic.ISet<T>
          duplicates.
<list>    An ordered collection that   System.Collections.IList
          allows duplicates            System.Collections.Generic.IList<T>



<bag>     An unordered collection      System.Collections.IList
          that allow duplicatd         System.Collections.Generic.IList<T>




                                                                          14
15
<class name=quot;Animalquot;>
   <id name=quot;Idquot;>
       <generator class=quot;nativequot; />
   </id>
   <discriminator column=quot;AnimalTypequot; length=quot;5quot; />
   <property name=quot;Namequot; />

   <subclass name=quot;Dogquot; discriminator-value=quot;Dogquot;>
       <property name=quot;Breedquot; />
   </subclass>
   <subclass name=“Frogquot; discriminator-value=“Frogquot;>
       <property name=“TongueLengthquot; />
   </subclass>
</class>




                                                       16
Pros
   Simple approach
   Easy to add new classes, you just need to add new
   columns for the additional data
   Data access is fast because the data is in one table
   Ad-hoc reporting is very easy because all of the data
   is found in one table.
Cons
   Coupling within the class hierarchy is increased
   because all classes are directly coupled to the same
   table. A change in one class can affect the table
   which can then affect the other classes in the
   hierarchy
   Space potentially wasted in the database
   Table can grow quickly for large hierarchies.         17
<class name=quot;Animalquot;>
   <id name=quot;Idquot;>
       <generator class=quot;nativequot; />
   </id>
   <property name=quot;Namequot; />
   <joined-subclass name=quot;Dogquot;>
       <key column=quot;Idquot; />
       <property name=quot;Breedquot; />
   </joined-subclass>
   <joined-subclass name=quot;Frogquot;>
       <key column=quot;Idquot; />
       <property name=quot;TongueLengthquot; />
   </joined-subclass>
</class>




                                          18
Pros
   Easy to understand because of the one-to-one
   mapping
   Very easy to modify superclasses and add new
   subclasses as you merely need to modify/add one
   table
   Data size grows in direct proportion to growth in the
   number of objects.
Cons
   There are many tables in the database, one for every
   class (plus tables to maintain relationships)
   Potentially takes longer to read and write data using
   this technique because you need to access multiple
   tables
   Ad-hoc reporting on your database is difficult, unless
   you add views to simulate the desired tables.            19
<class name=quot;Frogquot;>
   <id name=quot;Idquot;>
       <generator class=quot;nativequot; />
   </id>
   <property name=quot;Namequot; />
   <property name=quot;TongueLengthquot; />
</class>

<class name=quot;Dogquot;>
   <id name=quot;Idquot;>
       <generator class=quot;nativequot; />
   </id>
   <property name=quot;Namequot; />
   <property name=quot;Breedquot; />
</class>



                                      20
Pros
   Easy to do ad-hoc reporting as all the data you need
   about a single class is stored in only one table
   Good performance to access a single object’s data.
Cons
   When you modify a class you need to modify its table
   and the table of any of its subclasses.




                                                          21
22
23
Object oriented querying
    Increase compile-time syntax-checking
    Easy to write
    Hard to read
ICriteria crit = sess.CreateCriteria(typeof(Cat));
crit.SetMaxResults(50);
List topCats = crit.List();


IList cats = sess.CreateCriteria(typeof(Cat))
 .Add( Restrictions.Like(quot;Namequot;, quot;Fritz%quot;))
 .Add( Restrictions.Between(quot;Weightquot;, minWeight,
      maxWeight))
 .List();
                                                     24
String based querying
Object-Oriented SQL
Similar to SQL
Speak in terms of objects
Case sensitive
Very flexible
Zero compile-time syntax-checking

• from Customer c where c.Name like :name

• select count(*) from Customer c



                                            25
Powerful way to (simply) return a group of like objects
from the DB.
   Wonderfully simple to work with
   Great way to quickly process a “…where
   A=<something> and B=<something> and
   C=<something>…”
Cat cat = new Cat();
cat.Sex = 'F';
cat.Color = Color.Black;
List results = session.CreateCriteria(typeof(Cat))
      .Add( Example.Create(cat) )
      .List();



                                                          26
You can submit SQL statements to NHibernate if the
 other methods of querying a database do not fit your
 needs
 utilize database specific features

• sess.CreateSQLQuery(quot;SELECT * FROM CATSquot;)
      .AddScalar(quot;IDquot;, NHibernateUtil.Int32)
      .AddScalar(quot;NAMEquot;, NHibernateUtil.String)
      .AddScalar(quot;BIRTHDATEquot;, NHibernateUtil.Date);


• sess.CreateSQLQuery(quot;SELECT * FROM CATSquot;)
            .AddEntity(typeof(Cat));


                                                        27
28
29
Nhibernate.Contrib
   Mapping.Attributes
   Cache
   Search
   Validator
   Burrow
   LINQ to NHibernate
   Shards
Fluent Interface to NHibernate




                                 30
http://en.wikipedia.org/wiki/Object-relational_mapping
NHibernate in Action
NHibernate Reference Documentation 1.2.0
http://code.google.com/p/sharp-architecture/
http://www.codeproject.com/KB/database/Nhibernate_M
ade_Simple.aspx
http://www.codeproject.com/KB/architecture/NHibernate
BestPractices.aspx
www.hibernate.org
NHibernate FAQ
Summer of NHibernate


                                                     31
NHibernate (The ORM For .NET Platform)

More Related Content

What's hot

Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
Mumbai Academisc
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Manav Prasad
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
Marco Gralike
 
Hibernate
HibernateHibernate
Hibernate
Prashant Kalkar
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
Rajiv Gupta
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
Akshay Ballarpure
 
ODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XMLODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XML
Marco Gralike
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
Khoa Nguyen
 
XFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in thereXFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in there
Marco Gralike
 
Entity Framework
Entity FrameworkEntity Framework
Entity Framework
vrluckyin
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
XML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured dataXML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured data
Marco Gralike
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ram132
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To Hibernate
Amit Himani
 
BGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesBGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index Strategies
Marco Gralike
 
Miracle Open World 2011 - XML Index Strategies
Miracle Open World 2011  -  XML Index StrategiesMiracle Open World 2011  -  XML Index Strategies
Miracle Open World 2011 - XML Index Strategies
Marco Gralike
 
Entity framework
Entity frameworkEntity framework
Entity framework
icubesystem
 
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
Marco Gralike
 

What's hot (20)

Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
 
Hibernate
HibernateHibernate
Hibernate
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
ODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XMLODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XML
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
 
XFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in thereXFILES, The APEX 4 version - The truth is in there
XFILES, The APEX 4 version - The truth is in there
 
Entity Framework
Entity FrameworkEntity Framework
Entity Framework
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
XML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured dataXML Amsterdam - Creating structure in unstructured data
XML Amsterdam - Creating structure in unstructured data
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To Hibernate
 
BGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index StrategiesBGOUG 2012 - XML Index Strategies
BGOUG 2012 - XML Index Strategies
 
Miracle Open World 2011 - XML Index Strategies
Miracle Open World 2011  -  XML Index StrategiesMiracle Open World 2011  -  XML Index Strategies
Miracle Open World 2011 - XML Index Strategies
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
UKOUG 2010 (Birmingham) - XML Indexing strategies - Choosing the Right Index ...
 

Similar to NHibernate (The ORM For .NET Platform)

Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8
Nicolas Thon
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Baruch Sadogursky
 
Struts2
Struts2Struts2
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
Lukas Vlcek
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
goodfriday
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
dwm042
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Defense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMsDefense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMs
Vanessa Hurst
 
ORM JPA
ORM JPAORM JPA
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
Mark Menard
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
Mark Leith
 
REST dojo Comet
REST dojo CometREST dojo Comet
REST dojo Comet
Carol McDonald
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
google
 
Struts Tags Speakernoted
Struts Tags SpeakernotedStruts Tags Speakernoted
Struts Tags Speakernoted
Harjinder Singh
 
Basic Hibernate Final
Basic Hibernate FinalBasic Hibernate Final
Basic Hibernate Final
Rafael Coutinho
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
Daniel Egan
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
Doncho Minkov
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
Atlassian
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?
ukdpe
 

Similar to NHibernate (The ORM For .NET Platform) (20)

Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
 
Struts2
Struts2Struts2
Struts2
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
Building AOL's High Performance, Enterprise Wide Mail Application With Silver...
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Defense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMsDefense Against the Dark Arts: Protecting Your Data from ORMs
Defense Against the Dark Arts: Protecting Your Data from ORMs
 
ORM JPA
ORM JPAORM JPA
ORM JPA
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
 
REST dojo Comet
REST dojo CometREST dojo Comet
REST dojo Comet
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Struts Tags Speakernoted
Struts Tags SpeakernotedStruts Tags Speakernoted
Struts Tags Speakernoted
 
Basic Hibernate Final
Basic Hibernate FinalBasic Hibernate Final
Basic Hibernate Final
 
Linq To The Enterprise
Linq To The EnterpriseLinq To The Enterprise
Linq To The Enterprise
 
ASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And RepresentationASP.NET 08 - Data Binding And Representation
ASP.NET 08 - Data Binding And Representation
 
WPF and Databases
WPF and DatabasesWPF and Databases
WPF and Databases
 
Intro Open Social and Dashboards
Intro Open Social and DashboardsIntro Open Social and Dashboards
Intro Open Social and Dashboards
 
What's New for Data?
What's New for Data?What's New for Data?
What's New for Data?
 

More from Samnang Chhun

Find your passion
Find your passionFind your passion
Find your passion
Samnang Chhun
 
Software developer career growth
Software developer career growthSoftware developer career growth
Software developer career growth
Samnang Chhun
 
Why i love ruby than x
Why i love ruby than xWhy i love ruby than x
Why i love ruby than x
Samnang Chhun
 
12 Things Every Programmer Should Know
12 Things Every Programmer Should Know12 Things Every Programmer Should Know
12 Things Every Programmer Should Know
Samnang Chhun
 
The visitor design pattern
The visitor design patternThe visitor design pattern
The visitor design pattern
Samnang Chhun
 
Peforming Code Katas
Peforming Code KatasPeforming Code Katas
Peforming Code Katas
Samnang Chhun
 
Introduction To Share Vision
Introduction To Share VisionIntroduction To Share Vision
Introduction To Share Vision
Samnang Chhun
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Samnang Chhun
 
Version Control With Subversion
Version Control With SubversionVersion Control With Subversion
Version Control With Subversion
Samnang Chhun
 
Layering
LayeringLayering
Layering
Samnang Chhun
 

More from Samnang Chhun (10)

Find your passion
Find your passionFind your passion
Find your passion
 
Software developer career growth
Software developer career growthSoftware developer career growth
Software developer career growth
 
Why i love ruby than x
Why i love ruby than xWhy i love ruby than x
Why i love ruby than x
 
12 Things Every Programmer Should Know
12 Things Every Programmer Should Know12 Things Every Programmer Should Know
12 Things Every Programmer Should Know
 
The visitor design pattern
The visitor design patternThe visitor design pattern
The visitor design pattern
 
Peforming Code Katas
Peforming Code KatasPeforming Code Katas
Peforming Code Katas
 
Introduction To Share Vision
Introduction To Share VisionIntroduction To Share Vision
Introduction To Share Vision
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Version Control With Subversion
Version Control With SubversionVersion Control With Subversion
Version Control With Subversion
 
Layering
LayeringLayering
Layering
 

Recently uploaded

Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 

Recently uploaded (20)

Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 

NHibernate (The ORM For .NET Platform)

  • 1. Samnang Chhun (samnang@wowkhmer.com) Software Engineer, http://tech.wowkhmer.com
  • 2. Introduction to Object-Relational Mapping Introduction to NHibernate NHibernate Basics Mapping Inheritance hierarchies Advanced Querying Additional Reading 2
  • 3. 3
  • 4. Object-relational mapping (aka ORM, O/RM, and O/R mapping) is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages (Wikipedia) Objects are hierarchical Databases are relational ORM Objects Relational 4
  • 5. Performance or Scalability Productivity: less code to write/maintain Abstraction: transient to different DB technologies Simplification and Consistency Quality: depending on the product 5
  • 6. ADO.NET Entity Framework (released with .NET 3.5 SP1) Business Logic Toolkit for .NET Castle ActiveRecord IBatis.Net LightSpeed Linq (Language Integrated Query) LLBLGen LLBLGen Pro NHibernate Neo …etc 6
  • 7. 7
  • 8. Initially developed for Java created in late 2001 by Gavin King absorbed by the JBoss Group / Red Hat Ported to .NET 1.1, 2.0, 3.5 Resulting product called “NHibernate” All popular databases supported Oracle, SQL Server, DB2, SQLite, PostgreSQL, MySQL, Sybase, Firebird, … XML-based configuration files Good community support Free/open source - NHibernate is licensed under the LGPL (Lesser GNU Public License) 8
  • 9. RDBMS 9
  • 10. ISessionFactory One per database (or application) Expensive to create Reads configuration ISession Portal to the database Saves, retrieves ITransaction Encapsulates database transactions SessionFactory Session Transaction 10
  • 11. 11
  • 12. 12
  • 13. <class> declare a persistent class <id> defines the mapping from that property to the primary key column Specifies strategy <property> declares a persistent property of the class <component> maps properties of a child object to columns of the table of a parent class. Associations One-to-Many Many-to-One Many-to-Many One-to-One (uncommon) 13
  • 14. Element Description .NET Type <set> An unordered collection Iesi.Collections.ISet that does not allow Iesi.Collections.Generic.ISet<T> duplicates. <list> An ordered collection that System.Collections.IList allows duplicates System.Collections.Generic.IList<T> <bag> An unordered collection System.Collections.IList that allow duplicatd System.Collections.Generic.IList<T> 14
  • 15. 15
  • 16. <class name=quot;Animalquot;> <id name=quot;Idquot;> <generator class=quot;nativequot; /> </id> <discriminator column=quot;AnimalTypequot; length=quot;5quot; /> <property name=quot;Namequot; /> <subclass name=quot;Dogquot; discriminator-value=quot;Dogquot;> <property name=quot;Breedquot; /> </subclass> <subclass name=“Frogquot; discriminator-value=“Frogquot;> <property name=“TongueLengthquot; /> </subclass> </class> 16
  • 17. Pros Simple approach Easy to add new classes, you just need to add new columns for the additional data Data access is fast because the data is in one table Ad-hoc reporting is very easy because all of the data is found in one table. Cons Coupling within the class hierarchy is increased because all classes are directly coupled to the same table. A change in one class can affect the table which can then affect the other classes in the hierarchy Space potentially wasted in the database Table can grow quickly for large hierarchies. 17
  • 18. <class name=quot;Animalquot;> <id name=quot;Idquot;> <generator class=quot;nativequot; /> </id> <property name=quot;Namequot; /> <joined-subclass name=quot;Dogquot;> <key column=quot;Idquot; /> <property name=quot;Breedquot; /> </joined-subclass> <joined-subclass name=quot;Frogquot;> <key column=quot;Idquot; /> <property name=quot;TongueLengthquot; /> </joined-subclass> </class> 18
  • 19. Pros Easy to understand because of the one-to-one mapping Very easy to modify superclasses and add new subclasses as you merely need to modify/add one table Data size grows in direct proportion to growth in the number of objects. Cons There are many tables in the database, one for every class (plus tables to maintain relationships) Potentially takes longer to read and write data using this technique because you need to access multiple tables Ad-hoc reporting on your database is difficult, unless you add views to simulate the desired tables. 19
  • 20. <class name=quot;Frogquot;> <id name=quot;Idquot;> <generator class=quot;nativequot; /> </id> <property name=quot;Namequot; /> <property name=quot;TongueLengthquot; /> </class> <class name=quot;Dogquot;> <id name=quot;Idquot;> <generator class=quot;nativequot; /> </id> <property name=quot;Namequot; /> <property name=quot;Breedquot; /> </class> 20
  • 21. Pros Easy to do ad-hoc reporting as all the data you need about a single class is stored in only one table Good performance to access a single object’s data. Cons When you modify a class you need to modify its table and the table of any of its subclasses. 21
  • 22. 22
  • 23. 23
  • 24. Object oriented querying Increase compile-time syntax-checking Easy to write Hard to read ICriteria crit = sess.CreateCriteria(typeof(Cat)); crit.SetMaxResults(50); List topCats = crit.List(); IList cats = sess.CreateCriteria(typeof(Cat)) .Add( Restrictions.Like(quot;Namequot;, quot;Fritz%quot;)) .Add( Restrictions.Between(quot;Weightquot;, minWeight, maxWeight)) .List(); 24
  • 25. String based querying Object-Oriented SQL Similar to SQL Speak in terms of objects Case sensitive Very flexible Zero compile-time syntax-checking • from Customer c where c.Name like :name • select count(*) from Customer c 25
  • 26. Powerful way to (simply) return a group of like objects from the DB. Wonderfully simple to work with Great way to quickly process a “…where A=<something> and B=<something> and C=<something>…” Cat cat = new Cat(); cat.Sex = 'F'; cat.Color = Color.Black; List results = session.CreateCriteria(typeof(Cat)) .Add( Example.Create(cat) ) .List(); 26
  • 27. You can submit SQL statements to NHibernate if the other methods of querying a database do not fit your needs utilize database specific features • sess.CreateSQLQuery(quot;SELECT * FROM CATSquot;) .AddScalar(quot;IDquot;, NHibernateUtil.Int32) .AddScalar(quot;NAMEquot;, NHibernateUtil.String) .AddScalar(quot;BIRTHDATEquot;, NHibernateUtil.Date); • sess.CreateSQLQuery(quot;SELECT * FROM CATSquot;) .AddEntity(typeof(Cat)); 27
  • 28. 28
  • 29. 29
  • 30. Nhibernate.Contrib Mapping.Attributes Cache Search Validator Burrow LINQ to NHibernate Shards Fluent Interface to NHibernate 30
  • 31. http://en.wikipedia.org/wiki/Object-relational_mapping NHibernate in Action NHibernate Reference Documentation 1.2.0 http://code.google.com/p/sharp-architecture/ http://www.codeproject.com/KB/database/Nhibernate_M ade_Simple.aspx http://www.codeproject.com/KB/architecture/NHibernate BestPractices.aspx www.hibernate.org NHibernate FAQ Summer of NHibernate 31