-->
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.  [ 29 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Swing Threads Problem with ThreadLocal Session
PostPosted: Fri Dec 30, 2005 12:58 pm 
Newbie

Joined: Fri Dec 30, 2005 12:47 pm
Posts: 11
Hi... i am a begineers using Hibernate...

I am developing a Swing Application, and i am using thread (Foxtrot api) to managed swing events and avoid the freeze on swing components..

When a hibernate session is create and set in threadSession i receive a exception about: Two session open in the applications and nothing happens...

Please help me..


Top
 Profile  
 
 Post subject: tx
PostPosted: Fri Dec 30, 2005 1:41 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
You end up with two sessions because there are two threads are trying to do something. It should not be a problem if a some sort of AOP/proxy session management takes place. However you should be vary that because those threads are not in parent/child relationships the transaction propagation will be limited for a thread call chains. Most of the time it should not be a problem.
Please see this article for some information and ideas:
http://www.onjava.com/pub/a/onjava/2005 ... tions.html

Note: you do not have to use Spring, the same concept can be easily implemented with HiveMind, straight AspectJ, or CGLib enhancements.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 4:21 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is unnecessary and outdated stuff, Hibernate3 has built-in persistence context propagation on a thread. Please stop posting it as the cure-all whenever somebody doesn't understand transactions or threads.

http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: H not enough
PostPosted: Fri Dec 30, 2005 4:45 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I would not say that the article describes what needs to be done to complement
http://hibernate.org/42.html

Transaction demarcation has to be defined somewhere and proxy based interceptors are nice way of getting rid of repetitions of code like this:
try {
factory.getCurrentSession().beginTransaction();

// Do some work

} catch (RuntimeException e) {
factory.getCurrentSession().getTransaction().rollback();
throw e; // or display error message
}

The code goes in the interceptor and gets applied wisely by interceptor.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 5:18 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, and the interceptor is extremely trivial and has 10 lines of code (3 are important). You don't need a framework for the simple common case, and certainly not one that comes with 1000 page books.

http://cvs.sourceforge.net/viewcvs.py/h ... &view=auto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 5:52 pm 
Newbie

Joined: Fri Dec 30, 2005 12:47 pm
Posts: 11
Thanks.. i will try thats suggestiongs..


Top
 Profile  
 
 Post subject: framework
PostPosted: Fri Dec 30, 2005 6:35 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Christian,

It does not look like that interceptor actually does correct Transaction context propagation at least for JDBCTransaction.
The interceptor code starts and finishes transaction indeed, but I am afraid it might fail if the target method will call another instrumented class or method. In this case sequence will look like
transaction.begin()
transaction.begin()
transaction.commit()
transaction.commit() //what will happens here?


Method JDBCTransaction.begin() is reentrant, it does nothing if transaction already has started, but commit does its job on first invocation. I think JDBCTransaction should count begin requests and really commit transaction on matched commit call.
Or similar logic could be implemented in the interceptor ( stack based rather counter based approach ).

And some framework is necessary to apply interceptor, either JBossAOP or AspectJ, or simplified proxy bases solution like HiveMind, Spring, CGLib.

And JBossAOP is not the easiest to use IMO

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 7:20 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is for the _most common case_. No transaction propagation needed. And JBossAOP is one pointcut expressions to apply it to the right methods. Nothing is difficult about this.


Top
 Profile  
 
 Post subject: hmm
PostPosted: Fri Dec 30, 2005 7:38 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
christian wrote:
This is for the _most common case_. No transaction propagation needed. And JBossAOP is one pointcut expressions to apply it to the right methods. Nothing is difficult about this.

Wow! It is not that different from JDBC autocommit mode then, which is bad practice for production grade code.
I would say that most common is the situation where transaction propagation does required.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 8:00 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This has _nothing_ to do with auto commit mode.


Top
 Profile  
 
 Post subject: mode
PostPosted: Fri Dec 30, 2005 9:23 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
christian wrote:
This has _nothing_ to do with auto commit mode.

It is functionally close and that is bad IMO.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 9:35 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Dear Konstantin,

your assumption that "auto commit mode" is somehow connected to a simple transaction interceptor has nothing to do with reality. Please make things not more complex than they already are for poor Hibernate users. We still appreciate you helping out on our forums, but KISS.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 9:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
One of you is not reading the same thread when replying to the other one ;-p

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 9:44 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
emmanuel wrote:
One of you is not reading the same thread when replying to the other one ;-p

Most definitely :)

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 9:50 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Folks, I spent all week writing and explaining about transactions. I'm totally sick of it, I have to consider every little detail so that I don't cause more confusion with an already deeply confused and misled audience.

I have a real problem if someone makes my work even more difficult by spreading half-truth, "IMHO", and other things they have heard from their best buddy. Either put up or shut up if you don't have a point to make that holds water.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 29 posts ]  Go to page 1, 2  Next

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.