groovy - Grails Domain Object hasMany irregular behaviour using contains -
i'm having issue calling .contains() on 1 of domain classes' hasmany relationships not doing same when running normally, or when debugging. situation follows:
i have 2 domain objects, a , b. a has hasmany relationship b.
class { ... static hasmany = [bees: b] ... } now, during execution of 1 of filters, grab current user spring security service. user contains single instance of b. filter should check if instance of b in user contained in instance of a.
assume instances of b referring same object (since are).
now, issue arises. calling:
if (instanceofa.bees.contains(user.instanceofb)) { println 'success' } else { println 'failure' } prints failure during normal (or debugging without stepping through code) execution. however, if put break-point there, , step through code, correctly executes contains() , prints success.
i have implemented equals, hashcode , compareto in attempt resolve this, same behaviour.
this due lazyloading or cache. use instanceofa.bees.id.contains(user.instanceofb.id) , works.
Comments
Post a Comment