Clarifying terminology - What does “hydrating” a JPA or Hibernate entity mean when fetching the entity from the DB

后端 未结 6 1109
太阳男子
太阳男子 2020-12-04 20:54

In the context of ORM / Lazy loading of entities, my understanding of the term \"Hydration\" is as follows:

\"Hydrating\" describes the process of populating some or

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 21:11

    Hydration is a general ORM domain term meaning a method by which the query result is returned. It's not a process, not a verb, not an action or event that occurs but a noun. Therefore hydrating can only mean using a hydration, i.e. using that specific method, nothing else and brings nothing by itself therefore should never be used. A specific hydration can instantiate an object and populate it before returning its reference but hydrating in general doesn't mean populating. Different hydrations return different structures:

    • singular scalar
    • array of scalars
    • array of arrays
    • array of objects
    • object collecting scalars
    • object collecting arrays
    • object collecting other objects
    • ...more

    It's an ORM implementation detail. Some ORMs provide multiple hydrations and you can choose one by passing an argument to query builder, some don't give you that control and replace it by convention trying to be smart about it which usually leads to false assumptions.

提交回复
热议问题