Testing if a grails property is lazy/not initialized?
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",开发者_StackOverflow社区 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()
returned false
and for a String property - true
. Maybe FetchMode.LAZY
is not a guarantee - if you're requesting a simple type, it gets fetched anyway.
What is preferences
' type?
精彩评论