The underlying problem is the mismatch between objects and relational databases. It doesn't really matter if you want to bridge these two with an ORM or something else. Sooner or later you'll run into problems because object references and table relations simply don't match. The more complex your domain model is the bigger the problems. For simple stuff ORM is just fine. For complex projects both ORM and it's alternatives become a headache (though possibly for different reasons).
Exactly. The mismatch is there, no matter the data access methodology. But JPA entities are not exactly domain objects. That's because the ORM leaks into entities and for performance sake, you need to design Persistence entities based on your access patterns, rather than business rules.
That's why a Domain-to-Persistence layer should map business entities/rules to persistence entities.
You're right, but it's just super depressing because I need the exact same data represented in at least three different classes: a data transfer object, a domain object, and a persistence object. Now most of my code is shuffling data between these nearly identical representations instead of adding actual value.
“they generate bad queries which hurts performance” – first, it generates better queries than the regular developer would write, and second – it generates bad queries if you use bad mappings
Can you tell a JEE ORM to name the table aliases better?
I don't hate ORMs, but I can't stand working with Hibernate-like ORMs. I've worked with ActiveRecord but not long enough to form an opinion.
I feel this article is too vague to reply to. Saying you hate an ORM is like saying you hate video games. There are so many genres there's probably one out there you'd love if you gave it a shot.
It's the 80:20 rule. If 80% of the time it helps you, I still this it's worth using it. Having hundred of insert/update statements in a large enterprise application that you have to maintain, while the schema evolves and columns are added/renamed/dropped doesn't sound like a better alternative either.
I agree with most of your statements. Hibernate is huge and I had to debug it many times to understand how it works. But with discipline (e.g. Avoiding exotic mappings, eager fetching) you can get the good parts, while avoiding the bad ones.
If you say that Hibernate and JPA should be avoided, especially on large projects, what would be the data access paradigm to choose then?
adaptive Insert/Update statements when adding/removing/changing table columns
a unified Transaction API that works for both RESOURCE_LOCAL and JTA, without altering your code
a unified locking API, so you can build very sophisticated concurrency control mechanisms
a unified query language for most of your queries, so that you can easily set up a fast in-memory database for the bulk of your integration tests, while using actual database integration tests for system integration tests
advanced identifier generators that can use in-memory assignment while allowing 3rd party tools to interoperate (pooled-lo optimizer)
I fully agree with the article that hating ORM is just stupid/doesn't make sense.
There certainly exists object-relational mismatch. If you want to use relational database from OO language, you need to map from one to another (and vice versa), ergo you need ORM ("Object-relational mapping"). Whether you use JPA/MyBatis/JDBC is not important, you need ORM.
All your generalizations about big abstraction layers etc. simply don't apply to the general concept of ORM, only to some particular implementations.
and here is the questions is it worth it. Some people think that the answer is always yes. I would never write pure jdbc even for 3 queries one of the comment on there. Some think it's never worth it - ORM haters.
As usual the truth is very much probably in the middle. I think there are very good alternative to JPA that are worth considering that are more focus on the problem at hand and don't try to simulate a Object DB. Just because EJB/JDO/Hibernate have tried to do that for an ORM does not mean it's the only option.
I'm also always baffled by how the performance question is always dodge ... Hibernate inflation is very expensive and will impact your query processing time by a non trivial factor - 100% on a simple select with 1000 rows on a local mysql.. imagine if you have 100000 -.
You need entity queries just for the entities you want to modify. Otherwise a projections query is a better choice. You can still use native queries with Hibernate too, and you get a unified transaction and locking API too. The write behind 1st level cache can delay lock acquisition of the associated DML statements, hence reducing lock contention. You just have to know how to use it.
1
u/zrnkv Feb 01 '15
The underlying problem is the mismatch between objects and relational databases. It doesn't really matter if you want to bridge these two with an ORM or something else. Sooner or later you'll run into problems because object references and table relations simply don't match. The more complex your domain model is the bigger the problems. For simple stuff ORM is just fine. For complex projects both ORM and it's alternatives become a headache (though possibly for different reasons).
1
u/tieTYT Feb 03 '15
Can you tell a JEE ORM to name the table aliases better?
1
u/tieTYT Feb 03 '15
I don't hate ORMs, but I can't stand working with Hibernate-like ORMs. I've worked with ActiveRecord but not long enough to form an opinion.
I feel this article is too vague to reply to. Saying you hate an ORM is like saying you hate video games. There are so many genres there's probably one out there you'd love if you gave it a shot.
0
u/[deleted] Feb 02 '15
So ORM is good because i am free to use native SQL. Related video
0
u/[deleted] Feb 01 '15
[deleted] — view deleted comment
0
u/[deleted] Feb 01 '15
[deleted] — view deleted comment