I can’t seem to test if an object is lazy initialized. What am I doing wrong here?
public void testLazy(){
User lazyUser = User.withCriteria {
like("userId", 'test')
fetchMode("preferences", FetchMode.LAZY )
}.get(0)
assertFalse( "DOM objects of user were not lazy initialized",
GrailsHibernateUtil.isInitialized(lazyUser, "preferences") )
}
You’re doing all right.
Exactly same code piece worked for me – for a collection (of child domain objects) property,
isInitialized()returnedfalseand for a String property –true. MaybeFetchMode.LAZYis not a guarantee – if you’re requesting a simple type, it gets fetched anyway.What is
preferences‘ type?