Hacker News new | past | comments | ask | show | jobs | submit login

Code thinks in objects and functions and values and pointers.

Databases think in tables and columns and rows and queries and indexes.

If you don't pick an ORM to help manage this translation layer, then you'll end up re-implementing your own. Maybe this is OK, because yours will be simpler for quite some time.

What else are you going to do? Stored procedures? Concatenated strings?




No, you don't end up re-implementing your own, you end up implementing 10% of one. The 10% you need. Maybe it maps rows to objects, but doesn't handle object identity right, because that's not what you need.

The ideal for me is something that manages connections, lets me write the SQL, and gives me easy access to ResultSets, perhaps in the form of an object.

And yes, stored procedures are extremely useful, especially for minimizing chatter between the server and the database. Use them appropriately. (Although I don't see how they are an alternative to ORMs.)


Experience tells me you really need two layers. One for translating databases to objects, second one to translate those objects into proper domain objects.

The way code thinks about objects, behaviors and relationships is unlike the way you need to have it stored. Trying to use ORM-generated objects directly in a more complex business logic is, I learned, a recipe for disaster.

And since you're already writing two layers - data translation layer and actual domain layer - then, one may wonder, why not skip the first layer and implement the domain layer in terms of SQL queries?


I always feel that the arguments against ORMs is like the one against frameworks or using “Vanilla JS”. Saying you don’t use one really means you’re just writing your own.


> If you don't pick an ORM to help manage this translation layer, then you'll end up re-implementing your own.

Only in the loose sense that you have to put the data into an object. That's a tiny portion of what most ORMs actually do.

I just cloned the hibernate-orm repo and, even excluding the .git files and /test/ directories, it has about 30 MB of source. There's a lot in there.


Code can think just fine in tables and columns as well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: