What are benefits of using doctrine orm
Why use doctrine
- Around since 2006 with very stable, high-quality codebase.
- Extremely flexible and powerful object-mapping and query features.
- Support for both high-level and low-level database programming for all your use-cases.
- Large Community and integrations with many different frameworks (Symfony, Zend Framework, CodeIgniter, FLOW3, Lithium and more)
General definition of doctrine
The Doctrine Project is the home to several PHP libraries primarily focused on database storage and object mapping. The core projects are aObject Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon. Doctrine has greatly benefited from concepts of the Hibernate ORM and has adapted them to fit the PHP language.
Database Abstraction Layer
Powerful database abstraction layer with many features for database schema introspection, schema management and PDO abstraction.
Object Relational Mapper
Object relational mapper (ORM) for PHP that sits on top of a powerful database abstraction layer (DBAL). One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication.
What is Object/Relational Mapping?
If you are already familiar with Java, with Object/Relational Mapping, and with the Object/Relational mismatch, you may want to skip right to the Hibernate ORM benefits
Persistence in ORM
Hibernate ORM is concerned with helping your application to achieve persistence. So what is persistence? Persistence simply means that we would like our application’s data to outlive the applications process. In Java terms, we would like the state of (some of) our objects to live beyond the scope of the JVM so that the same state is available later.
Relational Databases in ORM
Specifically, Hibernate ORM is concerned with data persistence as it applies to relational databases (RDBMS). In the world of Object-Oriented applications, there is often a discussion about using anobject database (ODBMS) as opposed to a RDBMS. We are not going to explore that discussion here. Suffice it to say that RDBMS remain a very popular persistence mechanism and will so for the foreseeable future.
The Object-Relational Impedance Mismatch in ORM
‘Object-Relational Impedance Mismatch’ (sometimes called the ‘paradigm mismatch’) is just a fancy way of saying that object models and relational models do not work very well together. RDBMSs represent data in a tabular format (a spreadsheet is a good visualization for those not familiar with RDBMSs), whereas object-oriented languages, such as Java, represent it as an interconnected graph of objects. Loading and storing graphs of objects using a tabular relational database exposes us to 5 mismatch problems…?
Granularity in ORM
Sometimes you will have an object model which has more classes than the number of corresponding tables in the database (we says the object model is more granular than the relational model). Take for example the notion of an Address…?
Subtypes (inheritance) in ORM
Inheritance is a natural paradigm in object-oriented programming languages. However, RDBMSs do not define anything similar on the whole (yes some databases do have subtype support but it is completely non-standardized)…?
Identity in ORM
A RDBMS defines exactly one notion of ‘sameness’: the primary key. Java, however, defines both object identity
a==b and object equality
Associations in ORM
Associations are represented as unidirectional references in Object Oriented languages whereas RDBMSs use the notion of foreign keys. If you need bidirectional relationships in Java, you must define the association twice.
Likewise, you cannot determine the multiplicity of a relationship by looking at the object domain model.
Data navigation in ORM
The way you access data in Java is fundamentally different than the way you do it in a relational database. In Java, you navigate from one association to an other walking the object network.
This is not an efficient way of retrieving data from a relational database. You typically want to minimize the number of SQL queries and thus load several entities via JOINs and select the targeted entities before you start walking the object network.