DEV Community

Rumesh Madhusanka
Rumesh Madhusanka

Posted on

When to use/not use an ORM

ORMs ease out the pain of writing the data access layer by ourselves. But, have you ever come across a situation where an ORM is not suitable to do it's job?

Top comments (6)

Collapse
 
petros0 profile image
Petros Stergioulas • Edited

I was also struggling with that question.

I feel like for simple crud an orm is great and it doesn't add overhead.

If you complex relations and joins etc, maybe you should write the queries.

Collapse
 
rumeshmadhusanka profile image
Rumesh Madhusanka

For complex tasks, functions and procedures are handy. But ORMs build the database from scratch. Do ORMs allow functions, procedures..? πŸ€”

Collapse
 
petros0 profile image
Petros Stergioulas • Edited

I think yes. In some frameworks you can call a Procedure e.g. as a method with parameters and an output and then call it.

For example in java with spring-data-jpa (compination of Hibernate and Jpa) you can do something like this:

@Procedure(procedureName = "PROCEDURE_NAME")
boolean method0(@Param("param0") int param0);

source: logicbig.com/tutorials/spring-fram...

Also, I do not think it's wise to let ORM to build up your database (at least your production db). To build up a database, try better a migration tool.

Collapse
 
rumeshmadhusanka profile image
Rumesh Madhusanka

I guess some ORM's cannot do some complex tasks. In that case should we not use an ORM and use raw SQL OR use raw sql for the entire project?