« Return to Thread: domain relationships in shell / console

Re: domain relationships in shell / console

by Jon Evans :: Rate this Message:

Reply to Author | View in Thread

Hi Graeme,

On 12 Feb 2008, at 15:09, Graeme Rocher wrote:

This should work in the groovy console, the shell has a problem since
it was migrated to the new syntax highlighted one that means the
events aren't fired (which attach a hibernate session to each command)

It doesn't work in the console either:

c = Customer.get(1)
c.sites

[Cmd-R]
=======================

groovy> c = Customer.get(1)
groovy> c.sites

Result: 

=======================

and in the terminal window where I launched grails console, I get the same stack trace as before:

[41123] hibernate.LazyInitializationException failed to lazily initialize a collection of role: Customer.sites, no session or session was closed

[snip the rest]

This is grails 1.0 running on a Mac, BTW. Just in case this problem is caused by a plugin, I've just created a brand new app and added a simple pair of Customer / Site objects. Same error unfortunately.

Jon




Cheers

On Feb 12, 2008 3:03 PM, Jon Evans <jon@...> wrote:

Hi,

I'm trying to investigate the properties of relationships between domain
objects, using the groovy console or shell. I can't get it to load the
associations though.

/* trimmed down to remove irrelevant fields and methods */
class Customer {
       String name
       Set sites
       static hasMany = [ sites : Site ]
}

$ grails shell
[...]
groovy:000> c = Customer.get(1)
===> Customer One

groovy:000> c.sites
[92288] hibernate.LazyInitializationException failed to lazily initialize a
collection of role: Customer.sites, no session or session was closed
[snip massive stack trace]

I think I understand what's happening, but I need some code for the console
that says "execute the following block in the context of a valid Hibernate
session".

Thanks

Jon

Springy Web Springy Web Ltd
Jon Evans: jon@... / 07816 509261

 « Return to Thread: domain relationships in shell / console