-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Question about session implementation
PostPosted: Wed Sep 06, 2006 7:48 am 
Newbie

Joined: Wed Sep 06, 2006 7:03 am
Posts: 3
Hi,

I'm building a desktop application (SWT/JFACE) and I'm a little bit confused about the way I work with sessions. I started using the singleton class from Hibernate reference documentation. Then I realized that I will need something more complex. I tried different things and I realized that I'll probably need help...

The main problem for me is the Unit of Work and its scope.

For example in two different methods:

public void Method1() {
session = HibernateUtil.getSession();
... do some stuff ...
HibernateUtil.closeSession();
}

public void Method2() {
session = HibernateUtil.getSession();
... do some stuff ...
HibernateUtil.closeSession();
}

What if Method1 makes a call to Method2 before closing the session. Method2 will close the session (in singleton pattern of HibernateUtil) and then Method1 will have a problem.

Another solution is to open two sessions for the two Methods. But then I come to "org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions".

I could make it maybe if I can find out if an entity is currently associated with an open session. (This is a question on its own.)

If I'm not clear enough (I'm not clear enough for myself) I would be glad to discuss this in more detail.

Please any suggestions would be highly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 10:46 am 
Regular
Regular

Joined: Mon Jun 13, 2005 12:38 pm
Posts: 56
Location: Austin, TX
This may help you out:

http://static.springframework.org/sprin ... ml#d0e7576

It is in context to the Spring Framework, but you don't have to know spring to understand it.

Hope this helps.

-Mike


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 07, 2006 10:08 am 
Newbie

Joined: Wed Sep 06, 2006 7:03 am
Posts: 3
That did helped me out.

I did a little reading and found out that I somehow missed Contextual Sessions in Hibernate. That is what can help me. I will try to implement it in my app. If I have a problem I will write back.

Also if anybody wants to read something about Contextual Sessions these are short and usefull readings:

http://www.hibernate.org/hib_docs/v3/reference/en/html/architecture.html#architecture-current-session
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2005/04/
http://www.hibernate.org/42.html#A5


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.