« Return to Thread: domain relationships in shell / console

Re: domain relationships in shell / console

by fernando.takai :: Rate this Message:

Reply to Author | View in Thread

Jon,

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
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





--
Fernando "Takai"
http://flickr.com/photos/supeertakai
http://fernandotakai.tumblr.com/
http://twitter.com/fernando_takai

 « Return to Thread: domain relationships in shell / console