3 ms·
I wrote a fair bit of RoR app code in the past. Now I'm on the JVM and Hibernate is the equivalent of AR there: an ORM. We try to get rid of Hibernate were we
by cies 2y ago
I wrote a fair bit of RoR app code in the past.
Now I'm on the JVM and Hibernate is the equivalent of AR there: an ORM.
We try to get rid of Hibernate were we can: it is slow, comes with huuuuuge conceptual overhead (detachment/lifecycle/lazy/etc), makes it easy to write bad code (e.g. queries in loops), and you still need to know SQL (for complex queries that dont fit in the ORM).
So we use jOOQ now. Much better. Somthing that's AR also offers (but without the type safety). LINQ also has a similar interface (the one w/o the fancy syntax).
Alternatively there are tools like SQLDelight (Kotlin) and Sqlx (Rust). That provide an alternative path to "just use SQL" without resorting to queries-in-strings.
- Tainnor 2y agoAs someone who's worked in both stacks, I dislike both ActiveRecord and Hibernate for different reasons. ActiveRecord because it pushes the database layer into the model layer (and because Rails pushes the model layer into the view, this often leads to N+1 queries) - and Hibernate because it's a mess of optimisations that nobody understands, weird lazy loading behaviour, it saves records in the background when it feels like, has inscrutable transactional behaviour and wants be in charge of your database schema (thankfully you can turn that off). ActiveRecord's saving graces are a decent-ish query API and that it popularised migrations - Hibernate's that it encourages a repository pattern. As you write, jOOQ and similar are much better approaches. For Ruby, Sequel is a better library than AR for a number of reasons.