'Hibernate does null check initialize lazy entity?
Say I have an entity Parent with a related entity Child (nullable) with a @OneToMany(fetch = FetchType.LAZY) relationship
In my action bean, would the following code initialise the child entity?
boolean hasChild = false;
if(parent.getChild()!=null){
hasChild = true;
}
I see in the docs it says Lazy collection fetching: a collection is fetched when the application invokes an operation upon that collection. This is the default for collections. but wasn't sure if a null check is classed as an operation
Thanks
Solution 1:[1]
Null check can initialize entity. Use Hibernate.isInitialized() instead.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dev Joshi |
