当前位置:网站首页>Martin Fowler is tired of orm

Martin Fowler is tired of orm

2021-05-04 11:38:24 Jiedao jdon

Martin fowler A few years ago, I highly praised ORM( object / Relational database mapping framework ), especially Hibernate and Ruby Of Active Record, Now he is facing more and more people ORM Censure and doubt . He wrote the new article :ORM Tired of (OrmHate), Let's talk about the general idea of his article .

First ,MF by ORM The complexity is justified , Objects and relational databases have a natural impedance , Trying to reconcile always brings complexity . He also thinks :The object/relational mapping problem is hard, It's hard to try to map between objects and relational databases , Because you need to deal with data in two different views , One is in the relational database , Another one is in memory in-memory, These two are often caused by ORM Realization , It has nothing to do with the object , To be exact ,ORM It's actually in memory (in-memeory) Mapping with relational databases , Memory data structures are more flexible than relational models , Most people prefer to use this memory data structure , And then it's persisted to the database .

This mapping is much more complicated than we thought , Because once you change the data structure in memory , You have to map and synchronize to the other side , If there are multiple operations to modify the database at the same time, it is more complex ,ORM We have to deal with this concurrency , In this case you can't rely on the transaction mechanism , Because when you play with data in memory , You can't hold Living affairs ( Usually through database lock hold live ).

So is there ORM Instead of ?

MF Come up with two solutions :MF Think Hibernate and Active Record It's an expansion software , He saw a lot of people start to make their own systems ORM, It's very powerful , But they didn't realize they had fallen into the mire ,MF The mapping of object and relational database is just like Vietnam War in computer science .

Though many ORM The frame is like iBatis, Hibernate, and Active Record A lot of efforts have been made to solve many problems , But the key problem remains ,ORM To be able to solve 80%-90% The problem of , But the rest must be understood ORM And the internal working mechanism of the relational database .

MF Think that this is actually the correct use of ORM The way , He is in Ruby in Active Record The creator David Heinemeier Hansson For example ,ORM Help you deal with most of the boring junk code , But there's also a pipeline and a manhole , Let you deal directly with SQL sentence .

But people often complain , In order to make your object model more suitable ORM, Condescend to ORM, Can only become more relational ,MF Think this is the inevitable result of using relational database , You have to buy to make your memory model more relational , Or complicate your mapping code , To simplify your object and relational database mapping , You'd better make your domain model more relational , But that doesn't mean you have to design domain models based on relational models .

ORM It's complicated , Because it has to deal with bidirectional mapping , If there is only one-way mapping , The complexity of the problem may be solved , The premise is that you feel SQL Not complicated , This is it. CQRS( Read / write separation ).

版权声明
本文为[Jiedao jdon]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/05/20210504113758634j.html