When someone talks about hydrating an object, what does that mean?
当有人说到水合物体时,这意味着什么?
I see a Java project called Hydrate on the web that transforms data between different representations (RDMS to OOPS to XML). Is this the general meaning of object hydration; to transform data between representations? Could it mean reconstructing an object hierarchy from a stored representation?
我在web上看到一个名为Hydrate的Java项目,它在不同的表示之间转换数据(RDMS到OOPS to XML)。这是物体水合的一般意义吗?在表示之间转换数据?这是否意味着要从存储的表示中重构对象层次结构?
3 个解决方案
#1
67
With respect to the more generic term hydrate
Hydrating an object is taking an object that exists in memory, that doesn't yet contain any domain data ("real" data), and then populating it with domain data (such as from a database, from the network, or from a file system).
对一个对象进行水化处理是取一个存在于内存中的对象,该对象还不包含任何域数据(“真实”数据),然后用域数据(例如来自数据库、网络或文件系统)填充它。
From Erick Robertson's comments on this answer:
来自Erick Robertson对这个答案的评论:
deserialization == instantiation + hydration
反序列化=实例化+水合作用
If you don't need to worry about blistering performance, and you aren't debugging performance optimizations that are in the internals of a data access API, then you probably don't need to deal with hydration explicitly. You would typically use deserialization instead so you can write less code. Some data access APIs don't give you this option, and in those cases you'd also have to explicitly call the hydration step yourself.
如果您不需要担心膨胀的性能,也不需要调试数据访问API内部的性能优化,那么您可能不需要显式地处理水合。您通常会使用反序列化,这样您就可以编写更少的代码。有些数据访问api没有提供这种选项,在这种情况下,您还必须自己显式地调用水合步骤。
For a bit more detail on the concept of Hydration, see Erick Robertson's answer on this same question.
关于水合的概念,请参阅Erick Robertson的回答。
With respect to the Java project called hydrate
You asked about this framework specifically, so I looked into it.
你特别问过这个框架,所以我调查了一下。
As best as I can tell, I don't think this project used the word "hydrate" in a very generic sense. I see its use in the title as an approximate synonym for "serialization". As explained above, this usage isn't entirely accurate:
就我所知,我认为这个项目并没有把“水合物”这个词用在一般意义上。我认为它在标题中是“序列化”的近似同义词。如上所述,这种用法并不完全准确:
See: http://en.wikipedia.org/wiki/Serialization
参见:http://en.wikipedia.org/wiki/Serialization
translating data structures or object state into a format that can be stored [...] and reconstructed later in the same or another computer environment.
将数据结构或对象状态转换为可存储的格式[…然后在相同或不同的计算机环境中重建。
I can't find the reason behind their name directly on the Hydrate FAQ, but I got clues to their intention. I think they picked the name "Hydrate" because the purpose of the library is similar to the popular sound-alike Hibernate framework, but it was designed with the exact opposite workflow in mind.
我不能直接在水合物FAQ上找到他们名字背后的原因,但我得到了他们意图的线索。我认为他们选择了“Hydrate”这个名称,是因为这个库的目的与流行的类似于音的Hibernate框架相似,但它的设计思想与工作流完全相反。
Most ORMs, Hibernate included, take an in-memory object-model oriented approach, with the database taking second consideration. The Hydrate library instead takes a database-schema oriented approach, preserving your relational data structures and letting your program work on top of them more cleanly.
包括Hibernate在内的大多数ORMs都采用内存中面向对象模型的方法,其次考虑数据库。与之相反,Hydrate库采用面向数据库模式的方法,保存关系数据结构,并让程序更干净地处理它们。
Metaphorically speaking, still with respect to this library's name: Hydrate is like "making something ready to use" (like re-hydrating Dried Foods). It is a metaphorical opposite of Hibernate, which is more like "putting something away for the winter" (like Animal Hibernation).
打个比方,这个图书馆的名字仍然是这样的:水合物就像“做一些可以随时使用的东西”(就像重新水化干燥的食物)。它是冬眠的隐喻反义词,它更像是“放东西过冬”(比如动物冬眠)。
The decision to name the library Hydrate, as far as I can tell, was not concerned with the generic computer programming term "hydrate".
就我所知,命名图书馆水合物的决定与通用计算机编程术语“水合物”无关。
When using the generic computer programming term "hydrate", performance optimizations are usually the motivation (or debugging existing optimizations). Even if the library supports granular control over when and how objects are populated with data, the timing and performance don't seem to be the primary motivation for the name or the library's functionality. The library seems more concerned with enabling end-to-end mapping and schema-preservation.
当使用通用的计算机编程术语“水合物”时,性能优化通常是动机(或调试现有的优化)。即使库支持对对象何时以及如何填充数据进行粒度控制,时间和性能似乎也不是名称或库功能的主要动机。库似乎更关心端到端映射和模式保存。
#2
151
Hydration refers to the process of filling an object with data. An object which has not yet been hydrated has been instantiated and represents an entity that does have data, but the data has not yet been loaded into the object. This is something that is done for performance reasons.
水合作用是指用数据填充一个物体的过程。一个尚未水合物的对象已经被实例化并表示一个具有数据的实体,但是数据还没有被加载到对象中。这是出于性能原因而做的事情。
Additionally, the term hydration is used when discussing plans for loading data from databases or other data sources. Here are some examples:
此外,当讨论从数据库或其他数据源加载数据的计划时,使用术语水合作用。下面是一些例子:
You could say that an object is partially hydrated when you have only loaded some of the fields into it, but not all of them. This can be done because those other fields are not necessary for your current operations. So there's no reason to waste bandwidth and CPU cycles loading, transferring, and setting this data when it's not going to be used.
当你只将一些字段加载到一个对象中,而不是所有字段时,你可以说这个对象是部分水合物。可以这样做,因为其他字段对于当前操作没有必要。所以没有理由浪费带宽和CPU周期在不使用数据时加载、传输和设置数据。
Additionally, there are some ORM's, such as Doctrine, which do not hydrate objects when they are instantiated, but only when the data is accessed in that object. This is one method that helps to not load data which is not going to be used.
此外,还有一些ORM,比如Doctrine,它只在实例化对象时不对对象进行水合物处理,而是在对象中访问数据时才对其进行水合物处理。这是一种帮助不加载不使用的数据的方法。
#3
33
While it is somewhat redundant vernacular as Merlyn mentioned, in my experience it refers only to filling/populating an object, not instantiating/creating it, so it is a useful word when you need to be precise.
正如Merlyn提到的,它有点多余,但在我的经验中,它只指填充/填充对象,而不是实例化/创建对象,所以当您需要精确时,它是一个有用的词。
#1
67
With respect to the more generic term hydrate
Hydrating an object is taking an object that exists in memory, that doesn't yet contain any domain data ("real" data), and then populating it with domain data (such as from a database, from the network, or from a file system).
对一个对象进行水化处理是取一个存在于内存中的对象,该对象还不包含任何域数据(“真实”数据),然后用域数据(例如来自数据库、网络或文件系统)填充它。
From Erick Robertson's comments on this answer:
来自Erick Robertson对这个答案的评论:
deserialization == instantiation + hydration
反序列化=实例化+水合作用
If you don't need to worry about blistering performance, and you aren't debugging performance optimizations that are in the internals of a data access API, then you probably don't need to deal with hydration explicitly. You would typically use deserialization instead so you can write less code. Some data access APIs don't give you this option, and in those cases you'd also have to explicitly call the hydration step yourself.
如果您不需要担心膨胀的性能,也不需要调试数据访问API内部的性能优化,那么您可能不需要显式地处理水合。您通常会使用反序列化,这样您就可以编写更少的代码。有些数据访问api没有提供这种选项,在这种情况下,您还必须自己显式地调用水合步骤。
For a bit more detail on the concept of Hydration, see Erick Robertson's answer on this same question.
关于水合的概念,请参阅Erick Robertson的回答。
With respect to the Java project called hydrate
You asked about this framework specifically, so I looked into it.
你特别问过这个框架,所以我调查了一下。
As best as I can tell, I don't think this project used the word "hydrate" in a very generic sense. I see its use in the title as an approximate synonym for "serialization". As explained above, this usage isn't entirely accurate:
就我所知,我认为这个项目并没有把“水合物”这个词用在一般意义上。我认为它在标题中是“序列化”的近似同义词。如上所述,这种用法并不完全准确:
See: http://en.wikipedia.org/wiki/Serialization
参见:http://en.wikipedia.org/wiki/Serialization
translating data structures or object state into a format that can be stored [...] and reconstructed later in the same or another computer environment.
将数据结构或对象状态转换为可存储的格式[…然后在相同或不同的计算机环境中重建。
I can't find the reason behind their name directly on the Hydrate FAQ, but I got clues to their intention. I think they picked the name "Hydrate" because the purpose of the library is similar to the popular sound-alike Hibernate framework, but it was designed with the exact opposite workflow in mind.
我不能直接在水合物FAQ上找到他们名字背后的原因,但我得到了他们意图的线索。我认为他们选择了“Hydrate”这个名称,是因为这个库的目的与流行的类似于音的Hibernate框架相似,但它的设计思想与工作流完全相反。
Most ORMs, Hibernate included, take an in-memory object-model oriented approach, with the database taking second consideration. The Hydrate library instead takes a database-schema oriented approach, preserving your relational data structures and letting your program work on top of them more cleanly.
包括Hibernate在内的大多数ORMs都采用内存中面向对象模型的方法,其次考虑数据库。与之相反,Hydrate库采用面向数据库模式的方法,保存关系数据结构,并让程序更干净地处理它们。
Metaphorically speaking, still with respect to this library's name: Hydrate is like "making something ready to use" (like re-hydrating Dried Foods). It is a metaphorical opposite of Hibernate, which is more like "putting something away for the winter" (like Animal Hibernation).
打个比方,这个图书馆的名字仍然是这样的:水合物就像“做一些可以随时使用的东西”(就像重新水化干燥的食物)。它是冬眠的隐喻反义词,它更像是“放东西过冬”(比如动物冬眠)。
The decision to name the library Hydrate, as far as I can tell, was not concerned with the generic computer programming term "hydrate".
就我所知,命名图书馆水合物的决定与通用计算机编程术语“水合物”无关。
When using the generic computer programming term "hydrate", performance optimizations are usually the motivation (or debugging existing optimizations). Even if the library supports granular control over when and how objects are populated with data, the timing and performance don't seem to be the primary motivation for the name or the library's functionality. The library seems more concerned with enabling end-to-end mapping and schema-preservation.
当使用通用的计算机编程术语“水合物”时,性能优化通常是动机(或调试现有的优化)。即使库支持对对象何时以及如何填充数据进行粒度控制,时间和性能似乎也不是名称或库功能的主要动机。库似乎更关心端到端映射和模式保存。
#2
151
Hydration refers to the process of filling an object with data. An object which has not yet been hydrated has been instantiated and represents an entity that does have data, but the data has not yet been loaded into the object. This is something that is done for performance reasons.
水合作用是指用数据填充一个物体的过程。一个尚未水合物的对象已经被实例化并表示一个具有数据的实体,但是数据还没有被加载到对象中。这是出于性能原因而做的事情。
Additionally, the term hydration is used when discussing plans for loading data from databases or other data sources. Here are some examples:
此外,当讨论从数据库或其他数据源加载数据的计划时,使用术语水合作用。下面是一些例子:
You could say that an object is partially hydrated when you have only loaded some of the fields into it, but not all of them. This can be done because those other fields are not necessary for your current operations. So there's no reason to waste bandwidth and CPU cycles loading, transferring, and setting this data when it's not going to be used.
当你只将一些字段加载到一个对象中,而不是所有字段时,你可以说这个对象是部分水合物。可以这样做,因为其他字段对于当前操作没有必要。所以没有理由浪费带宽和CPU周期在不使用数据时加载、传输和设置数据。
Additionally, there are some ORM's, such as Doctrine, which do not hydrate objects when they are instantiated, but only when the data is accessed in that object. This is one method that helps to not load data which is not going to be used.
此外,还有一些ORM,比如Doctrine,它只在实例化对象时不对对象进行水合物处理,而是在对象中访问数据时才对其进行水合物处理。这是一种帮助不加载不使用的数据的方法。
#3
33
While it is somewhat redundant vernacular as Merlyn mentioned, in my experience it refers only to filling/populating an object, not instantiating/creating it, so it is a useful word when you need to be precise.
正如Merlyn提到的,它有点多余,但在我的经验中,它只指填充/填充对象,而不是实例化/创建对象,所以当您需要精确时,它是一个有用的词。