Using lazy for properties in Hibernate

前端 未结 3 1345
一个人的身影
一个人的身影 2021-01-03 05:41

The lazy attribute for property tag in hibernate allows to lazily load the property as per the link: http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/mapping.htm

3条回答
  •  我在风中等你
    2021-01-03 06:26

    Lazy loading is just a hint to your persistence provider. This hint does not provide any guarantees that the entities will be actually loaded lazily.

    The provider is free to load them eagerly if this is determined to be a better approach by the provider.

    Especially basic properties will rarely be loaded lazily, as it does not boost performance to load them lazily, rather the opposite.

    The behaviour may vary depending on the context, so lazy loading is impossible to test for reliably. Eager loading (the default) on the other hand is guaranteed and can be tested for.

    EDIT If you just want to see the effects of lazy loading - lazy loading is more likely to occur when the lazily loaded attributes are relations to other entities or LOBs.

提交回复
热议问题