开发者

Testing if a grails property is lazy/not initialized?

开发者 https://www.devze.com 2023-02-27 09:44 出处:网络
I can\'t seem to test if an object is lazy initialized. What am I doing wrong here? public void testLazy(){

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号