You have to call Hibernate.initialize() on all collections, that are lazy 
loaded, e.g.:

Hibernate.initialize(person.getAddresses());
Hibernate.initialize(person.getPhoneNumbers()); 
...

Did you try that?

In my application, my "getAll()" method only returns lazy initialized objects. 
I then overwrote "get(Serializable id)" from the GenericDao in my DAO 
implementations and fully initialize the objects there, using 
Hibernate.initialize(). This way, for object lists (e.g. Jtable) only the 
needed data is loaded. For opening the details view of an object, I call 
get(id) and pass this fully initialized object to my DetailsView.

Maybe this is will work for your app, too.

Kind regards,
Tobias

-----Ursprüngliche Nachricht-----
Von: MarcelR [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 29. Juni 2007 13:02
An: [email protected]
Betreff: Re: [appfuse-user] Appfuse Core + Swing: Session is closed


I tried both (everything EAGER (actually only an int and String) and
Hibernate.initialize() in the constructor of a 'model' POJO). But still get 
"Session is closed".

Isn't there a way to control the hibernate sessions and open/close them using 
an aspect advisor like with the transactions? 


mraible wrote:
> 
> If you're not using a web framework, you should probably not use lazy 
> initialization. You can use Hibernate.initialize() on your POJO to 
> initialize all it's children. Either that, or change or FetchType to 
> EAGER.
> 
> Matt
> 
> On 6/27/07, MarcelR <[EMAIL PROTECTED]> wrote:
>>
>> I try to use the Appfuse 2m5 core with a Swing UI instead of a web 
>> interface.
>>
>> For this generated a core app. (quick start) with a jpa-hibernate as ORM.
>> I created a few testcases to test e.g. get(id) and getAll for the 
>> userDao.
>> This works without any problems.
>>
>> Then when I use a Swing databinding framework the problems start.
>> I first tried  http://oswing.sourceforge.net/ OpenSwing  and after 
>> that https://genesis.dev.java.net/nonav/3.0/maven-site/en/index.html Genesis 
>> .
>> But with both I get the same error when I try to use the dao for 
>> getAll(), but NOT for get(id).
>> Anybody knows how I can keep the session opened (or how the session 
>> gets closed).
>> Do I need something like
>> org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter?
>>
>>
>> Here's the first part of the stacktrace:
>>
>> org.hibernate.SessionException: Session is closed!
>>    at
>> org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
>>    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1110)
>>    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
>>    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
>>    at org.appfuse.dao.jpa.GenericDaoJpa.getAll(GenericDaoJpa.java:45)
>>    at
>> com.labiron.masa.swing.companyPart.LoginForm.populate(LoginForm.java:86)
>>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>
>>
>> I hope anybody can give me some hint to go on.
>>
>> Marcel
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Appfuse-Core-%2B-Swing%3A-Session-is-closed-tf3
>> 987393s2369.html#a11321723 Sent from the AppFuse - User mailing list 
>> archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> --
> http://raibledesigns.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

--
View this message in context: 
http://www.nabble.com/Appfuse-Core-%2B-Swing%3A-Session-is-closed-tf3987393s2369.html#a11358469
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to