You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by James Sherwood <js...@rgisolutions.com> on 2009/02/05 19:18:47 UTC

T5: Hibernate/Session question

Hello,

 

I have an application state object(Visit) that is storing a hibernate entity
object.

 

In a page I ask for the visit.object.getchildobject.name and receive this
error:

 

[ERROR] hibernate.LazyInitializationException could not initialize proxy -
the owning Session was closed

org.hibernate.LazyInitializationException: could not initialize proxy - the
owning Session was closed

 

 

Can I not do this from application state objects?

 

Thanks,

--James

 


Re: T5: Hibernate/Session question

Posted by Sven Homburg <ho...@googlemail.com>.
ok ;-)

2009/2/5 Thiago H. de Paula Figueiredo <th...@gmail.com>

> Em Thu, 05 Feb 2009 17:07:24 -0300, Sven Homburg <ho...@googlemail.com>
> escreveu:
>
>  i prefer you to use the session.refresh
>>
>
> This will overwrite your object, and sometimes you want it unchanged. As
> always, the best option depends on the context. ;)
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
with regards
Sven Homburg
http://www.chenillekit.org
http://tapestry5-components.googlecode.com

Re: T5: Hibernate/Session question

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 05 Feb 2009 17:07:24 -0300, Sven Homburg <ho...@googlemail.com>  
escreveu:

> i prefer you to use the session.refresh

This will overwrite your object, and sometimes you want it unchanged. As  
always, the best option depends on the context. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Hibernate/Session question

Posted by Sven Homburg <ho...@googlemail.com>.
i prefer you to use the session.refresh

2009/2/5 James Sherwood <js...@rgisolutions.com>

> Hello,
>
> I used session.update(Object) and it worked, is there any difference?
>
> --James
>
> -----Original Message-----
> From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com]
> Sent: February-05-09 4:48 PM
> To: Tapestry users
> Subject: Re: T5: Hibernate/Session question
>
> Em Thu, 05 Feb 2009 15:59:53 -0300, James Sherwood
> <js...@rgisolutions.com> escreveu:
>
> > Thanks,
> >
> > I do not want to have to change the actual POJOs as I generate them using
> > reverse eng so I think I will just do the lookup.\
>
> One solution is to call session.lock(object, LockMode.NONE) before reading
> any property values. It associates the object with the given session, thus
> avoiding the LazyInstantiationException's. ;)
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
with regards
Sven Homburg
http://www.chenillekit.org
http://tapestry5-components.googlecode.com

Re: T5: Hibernate/Session question

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 05 Feb 2009 16:58:39 -0300, James Sherwood  
<js...@rgisolutions.com> escreveu:

> Hello,

Hi!

> I used session.update(Object) and it worked, is there any difference?

session.update(Object) writes the object to the database, session.lock()  
not. Both associate the object to the session, so use one or the other  
depending on what you need. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: T5: Hibernate/Session question

Posted by James Sherwood <js...@rgisolutions.com>.
Hello,

I used session.update(Object) and it worked, is there any difference?

--James

-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: February-05-09 4:48 PM
To: Tapestry users
Subject: Re: T5: Hibernate/Session question

Em Thu, 05 Feb 2009 15:59:53 -0300, James Sherwood  
<js...@rgisolutions.com> escreveu:

> Thanks,
>
> I do not want to have to change the actual POJOs as I generate them using
> reverse eng so I think I will just do the lookup.\

One solution is to call session.lock(object, LockMode.NONE) before reading  
any property values. It associates the object with the given session, thus  
avoiding the LazyInstantiationException's. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Hibernate/Session question

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 05 Feb 2009 15:59:53 -0300, James Sherwood  
<js...@rgisolutions.com> escreveu:

> Thanks,
>
> I do not want to have to change the actual POJOs as I generate them using
> reverse eng so I think I will just do the lookup.\

One solution is to call session.lock(object, LockMode.NONE) before reading  
any property values. It associates the object with the given session, thus  
avoiding the LazyInstantiationException's. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: T5: Hibernate/Session question

Posted by James Sherwood <js...@rgisolutions.com>.
Thanks,

I do not want to have to change the actual POJOs as I generate them using
reverse eng so I think I will just do the lookup.\

Just making sure I was not doing something wrong:)

--James

-----Original Message-----
From: Sven Homburg [mailto:homburgs@googlemail.com] 
Sent: February-05-09 2:23 PM
To: Tapestry users
Subject: Re: T5: Hibernate/Session question

there are two possible solutions:

first: you declare the collection for childobjects "read not lazy"

second: you attach the parentobject to a new session and re-read the
childobjects collection


2009/2/5 James Sherwood <js...@rgisolutions.com>

> Hello,
>
>
>
> I have an application state object(Visit) that is storing a hibernate
> entity
> object.
>
>
>
> In a page I ask for the visit.object.getchildobject.name and receive this
> error:
>
>
>
> [ERROR] hibernate.LazyInitializationException could not initialize proxy -
> the owning Session was closed
>
> org.hibernate.LazyInitializationException: could not initialize proxy -
the
> owning Session was closed
>
>
>
>
>
> Can I not do this from application state objects?
>
>
>
> Thanks,
>
> --James
>
>
>
>


-- 
with regards
Sven Homburg
http://www.chenillekit.org
http://tapestry5-components.googlecode.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Hibernate/Session question

Posted by Sven Homburg <ho...@googlemail.com>.
there are two possible solutions:

first: you declare the collection for childobjects "read not lazy"

second: you attach the parentobject to a new session and re-read the
childobjects collection


2009/2/5 James Sherwood <js...@rgisolutions.com>

> Hello,
>
>
>
> I have an application state object(Visit) that is storing a hibernate
> entity
> object.
>
>
>
> In a page I ask for the visit.object.getchildobject.name and receive this
> error:
>
>
>
> [ERROR] hibernate.LazyInitializationException could not initialize proxy -
> the owning Session was closed
>
> org.hibernate.LazyInitializationException: could not initialize proxy - the
> owning Session was closed
>
>
>
>
>
> Can I not do this from application state objects?
>
>
>
> Thanks,
>
> --James
>
>
>
>


-- 
with regards
Sven Homburg
http://www.chenillekit.org
http://tapestry5-components.googlecode.com