简体   繁体   English

使用ORM时耦合数据库交互的耦合程度如何

[英]How loose coupling DB interaction when using ORM

I am really struggling with understanding how you are loose coupling your app with a DB when you use an ORM. 我真的很难理解您在使用ORM时如何松散地将应用程序与数据库耦合。 I understand there are code first and data first design patterns and in some scnearios (Straight forward schemas....some e-commerce, etc) this makes sense. 我知道有代码优先和数据优先的设计模式,在某些场景中(直截了当的模式...某些电子商务等),这很有意义。 When you have more complex and / or changing schemas during a development phase how do you not handcuff yourself with tightly coupling to the DB. 当您在开发阶段具有更复杂和/或更改模式时,如何不与数据库紧密耦合就束手无策。

I am just trying to understand how to apply a valid / robust process for dealing with typical changes to data structures. 我只是想了解如何应用有效/健壮的过程来处理数据结构的典型更改。

Thanks, 谢谢,

S 小号

You are tightly coupled to the ORM tool, but not the DB. 您与ORM工具紧密相关,但与DB紧密相关。 You can take your complete application and move it to another database with just a few lines changed in your hibernate configuration. 您可以将完整的应用程序移到另一个数据库中,只需在休眠配置中更改几行即可。 By changing the database dialect, and the jdbc url to match the new database server, you can port your application from MySql, to PostgreSQL, to Oracle, to SqlServer. 通过更改数据库方言和jdbc URL以匹配新的数据库服务器,可以将应用程序从MySql移植到PostgreSQL,Oracle到SqlServer。 That's the loose coupling. 那是松散的耦合。

a way of dealing with data structure changes is via migrations. 处理数据结构更改的一种方法是通过迁移。 but ORMs are not really designed for that task, so you mostly end up with migrations somehow scripted/implemented by your own, see data-migration-with-hibernate 但是ORM并非真正针对该任务而设计的,因此您通常最终会以某种方式由自己编写脚本/实现迁移 ,请参见休眠时数据迁移

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM