r/programming 8d ago

Solving the 1+N Query Problem

https://acadia.engineering/blog/solving-the-1-plus-N-query-problem
128 Upvotes

94 comments sorted by

View all comments

28

u/JimmyM_1 8d ago

I don't know why people hate on ORMs for this one, yes abstracting SQL can lead some devs to forget / not even know about what is actually happening under the hood, but it isn't that big of a deal!

Make sure your dev team is aware of the JOIN concept and you're good to go!

9

u/Schmittfried 7d ago

To be fair, after using Laravel’s ORM and Hibernate, I’m pretty amazed how far ahead django’s ORM is in terms of usability and making the efficient implementation the path of least resistance. You really have to jump through some hoops to make certain joins efficient with Hibernate that would be trivial with the django ORM. 

3

u/baseballlover723 7d ago edited 7d ago

To be fair, after using Laravel’s ORM and Hibernate, I’m pretty amazed how far ahead django’s ORM is in terms of usability and making the efficient implementation the path of least resistance.

As a ruby person, I never got all the hate that ORMs got, since ActiveRecord was excellent (even if you could still footgun yourself) and I usually felt like I was basically writing sql via ruby DSL most of the time. Never had issues with the simple handful of tables with a few connections between them with it that most uncomplicated DBs look like.

And then I used Hibernate, and I now understand why everyone hates ORMs. I couldn't get forward and backward full object links between relations. I couldn't figure out how to get it to be able to choose if it should load all the sub relations or not. I had N+1 issues because JPA was too dumb to group them all together. I also couldn't get composite primary keys to work with relations either. Just everything felt like it was made hard for no real reason. And the DB isn't even that complicated. It's still a handful of tables with some connections between them.

So now I understand. People don't hate ORMs. They hate shitty ORMs. And there are evidently some popular and shitty ORMs still around for some reason.

3

u/Absolute_Enema 6d ago

 Just everything felt like it was made hard for no real reason

Old Java libs in a nutshell.