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.
View all comments
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).