code_junkie

How to reference a Grails domain class fields from outside of the Grails controller and view?

Nov 13th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. class Child {
  2. static hasMany = [ toys : Toy ]
  3. String name
  4. Set toys
  5. }
  6. class Toy {
  7. static belongsTo = [ owner : Child ]
  8. String name
  9. }
  10.  
  11. child = Child.findByName("Joe")
  12.  
  13. child = Child.findById(123)
  14.  
  15. child.getToys()
  16.  
  17. org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: Child.toys, no session or session was closed
  18.  
  19. child = Child.findByName("Joe", [ fetch: [ toys: 'eager' ] ] )
Add Comment
Please, Sign In to add comment