What is ORM? Why is it used? What are its pros and cons?

Kader Genç
2 min readMay 20, 2023

--

What is ORM?

ORM is a communication tool between your project and the database. You can perform database connection and query operations using ORM in your project. Some of the common advantages of ORM include the ability to convert class properties to tables instead of creating tables on the database manually. Additionally, the general queries that come with ORM allow us to perform operations on the database without the need to write any database code.

ORM first maps the entity properties to record them in a special format (like XML). It connects to the database with connection information (config file) and creates tables by querying with the information it has saved.

ORM Pros and Cons?

Pros:

  • The connection between ORM and the database is not dependent on what the database is, making it easier to switch to another database.
  • ORM automation reduces the likelihood of errors in most database operations.
  • Since ORM supports many programming languages, you can use the database you want in the programming language you want.
  • ORM supports custom queries, so you can use your own queries with ORM.

Cons:

  • If we delete the entity we created while using ORM, the table in the database will not be deleted. Therefore, both sides must be operated in case of any discrepancies between the code and the database.
  • Similarly, if the name of the existing entity changes, a new table will be created for that name. Since the old table will not be overwritten, data is stored in two different places, causing inconsistency.
  • Due to the limited types that ORM accepts, you may have to store data in a more limited way.
  • ORM architecture may cause performance loss.

Some ORM tools:

  • C#: Entity Framework, Dapper, ECO, XPO, Norm
  • Java: Hibernate, Ebean, Torque, JPA, MyBattis, JOOQ
  • Python: Django, South, Storm
  • .NET Framework: NHibernate
  • JavaScript: Knex.js, SQL Query Builder, Sequelize, Bookshelf, Waterline, Objection.js, Mongoose, Typegoose, TypeORM, MikroORM, Prisma

Thank you for reading. See you in other articles. 🧡

--

--