Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

CMT with Spring/Hibernate

 
author
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, let me welcome the authors.

Second, I don't know whether this is more of a Hibernate question than it is a Spring question, but I'll ask it just the same. From what I understand, one can use Spring to provide container-managed transactions when using Hibernate. I am certainly interested in this feature, as well as its impact on testing. Can you recommend a tutorial or overview? I've read the relevant Hibernate documentation and didn't find it terribly clear.

Take care.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

Spring supports declarative transactions by means of "proxy beans". Let's say you have a bean named "stockBroker" in your configuration file. Now, you want the StockBroker bean to participate in a transaction so you rename "stockBroker" to "stockBrokerTarget" and create a new bean named "stockBroker" that makes use of Spring's built-in TransactionProxyFactoryBean telling it to delegate to "stockBroker" and to apply some specific transaction attributes like ISOLATION_READ_COMMITTED, TRANSACTION_SUPPORTS, etc. (I probably got those names wrong but you get the idea).
 
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse,

Do you mean Proxy Bean to access EJBs ?? (sorry, but I'm not really used to Spring vocabulary)
So that you can have CMT capabilities only using EJBs ?? Am I lost ?
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by JeanLouis Marechaux:
Lasse,

Do you mean Proxy Bean to access EJBs ?? (sorry, but I'm not really used to Spring vocabulary)
So that you can have CMT capabilities only using EJBs ?? Am I lost ?



No. Not EJB Just a java bean. A proxy that provides CMT ( container is Spring itself) before delegating to the java bean that does the actual work.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Karthik Guru:
No. Not EJB Just a java bean. A proxy that provides CMT ( container is Spring itself) before delegating to the java bean that does the actual work.


Exactly. In Spring terminology, a "bean" is a POJO, although you can configure EJB home interfaces ("Hey Spring, when I ask for a bean named 'myEJB', please fetch me an EJBHome implementation with this JNDI name") as Spring beans as well.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, so the Spring container (Spring Core ??) has its own implementation of Transactions and provides a CMT feature....
[ February 23, 2005: Message edited by: JeanLouis Marechaux ]
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by JeanLouis Marechaux:
ok, so the Spring container (Spring Core ??) as its own implementation of Transactions and provides a CMT feature....



No it does NOT have its own implementation. It delegates to the underlying implementation. Can be a j2ee container, hibernate , jdo impl etc.
But as for he actual CMT part yes it does this by applying interceptors.
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Karthik Guru:


No it does NOT have its own implementation. It delegates to the underlying implementation. Can be a j2ee container, hibernate , jdo impl etc.
But as for he actual CMT part yes it does this by applying interceptors.




Could you elaborate on this. Interceptors ??
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AOP interceptors. Spring implements the declarative transactions by attaching an interceptor to a bean and that interceptor intercepts incoming methods (as per configuration) to decide whether Spring should create a new transaction (using whatever transaction manager has been configured), suspend an existing transaction, or reject the method call if the transactional context does not match the bean's requirements.

Here's an example of how you declare transactional boundaries in Spring (again, from "Spring in Action"):

[ February 23, 2005: Message edited by: Lasse Koskela ]
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:
AOP interceptors. Spring implements the declarative transactions by attaching an interceptor to a bean and that interceptor intercepts incoming methods (as per configuration) to decide whether the user is authorized to invoke that particular method.



Are we talking about transaction management or security here Laase
I suppose CMT is done using AOP, so that demarcation code is added to the source code (begin and end JTA transaction s mostly).
Then you need a JTA implementation because Spring does not have an embedded one
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by JeanLouis Marechaux:
Are we talking about transaction management or security here Laase

Darn. I wasn't quite fast enough

Originally posted by JeanLouis Marechaux:
I suppose CMT is done using AOP, so that demarcation code is added to the source code (begin and end JTA transaction s mostly).
Then you need a JTA implementation because Spring does not have an embedded one

Actually, Spring uses either dynamic proxies (for interfaces) or CGLIB (for classes) to weave in the aspects.

Also, you still don't need a JTA implementation unless you need distributed (XA) transactions. If you only need to talk to one database within one transaction, you can just use the transaction manager of the supported persistence frameworks: DataSourceTransactionManager for JDBC, HibernateTransactionManager for Hibernate, JdoTransactionManager for JDO, or PersistenceBrokerTransactionManager for OJB (and of course JtaTransactionManager).
 
JeanLouis Marechaux
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:


Darn. I wasn't quite fast enough



Sorry Lasse, but that's because I was really eager to read your comments
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!