|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
domain relationships in shell / consoleHi,
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 |
|
|
Re: domain relationships in shell / consoleThis 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) 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 > -- > View this message in context: http://www.nabble.com/domain-relationships-in-shell---console-tp15434264p15434264.html > Sent from the grails - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > -- Graeme Rocher Grails Project Lead G2One, Inc. Chief Technology Officer http://www.g2one.com --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: domain relationships in shell / consoleJon,
I've found this: import org.hibernate.Session import org.hibernate.SessionFactory import org.springframework.orm.hibernate3.SessionFactoryUtils import org.springframework.orm.hibernate3.SessionHolder import org.springframework.transaction.support.TransactionSynchronizationManager sessionFactory = ctx.getBean("sessionFactory") session = SessionFactoryUtils.getSession(sessionFactory, true) TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)) I've tried to load some collections on shell and worked. Try it see if it works w/ you. On Feb 12, 2008 1:09 PM, Graeme Rocher <graeme@...> wrote: This should work in the groovy console, the shell has a problem since -- Fernando "Takai" http://flickr.com/photos/supeertakai http://fernandotakai.tumblr.com/ http://twitter.com/fernando_takai |
|
|
Re: domain relationships in shell / consoleHi Graeme,
On 12 Feb 2008, at 15:09, Graeme Rocher wrote:
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
|
|
|
Re: domain relationships in shell / consoleHi Fernando,
On 12 Feb 2008, at 15:21, Fernando wrote: > I've found this: > > import org.hibernate.Session > import org.hibernate.SessionFactory > import org.springframework.orm.hibernate3.SessionFactoryUtils > import org.springframework.orm.hibernate3.SessionHolder > import > org > .springframework.transaction.support.TransactionSynchronizationManager > sessionFactory = ctx.getBean("sessionFactory") > session = SessionFactoryUtils.getSession(sessionFactory, true) > TransactionSynchronizationManager.bindResource(sessionFactory, new > SessionHolder(session)) > > I've tried to load some collections on shell and worked. > > Try it see if it works w/ you. Yes, it seems to work fine here too. Thanks for the info. Jon --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: domain relationships in shell / consoleHi,
On 12 Feb 2008, at 15:21, Fernando wrote: > I've found this: > > import org.hibernate.Session > import org.hibernate.SessionFactory > import org.springframework.orm.hibernate3.SessionFactoryUtils > import org.springframework.orm.hibernate3.SessionHolder > import > org > .springframework.transaction.support.TransactionSynchronizationManager > sessionFactory = ctx.getBean("sessionFactory") > session = SessionFactoryUtils.getSession(sessionFactory, true) > TransactionSynchronizationManager.bindResource(sessionFactory, new > SessionHolder(session)) > Is there a file I can add that to so that it gets executed automatically whenever I invoke "grails shell"? It's getting a bit tedious copying and pasting it in every time. :) Thanks Jon --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |