Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to configure Transaction in Spring and Hibernate Annotation?..

 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends..

i have any question..
how to configure Transaction in application which developed in Spring and Hibernate?..
i use Spring just as IoC..

which one is good for implementation..
do i have to use JTA or i just use Embedded Transaction which provided by Spring?..

now.. i do like this one in Spring container..


and in My DAO :


is it can accepted as Simple Transaction?..
or i have to use JTA?..

is it any link for integrating between Spring IoC, Hibernate/JPA, and JTA?..

Thanks all..
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excerpt from Spring official doc. For more read on...

The Spring Framework's transaction management support significantly changes traditional thinking as to when a J2EE application requires an application server.

In particular, you don't need an application server just to have declarative transactions via EJB. In fact, even if you have an application server with powerful JTA capabilities, you may well decide that the Spring Framework's declarative transactions offer more power and a much more productive programming model than EJB CMT.

Typically you need an application server's JTA capability only if you need to enlist multiple transactional resources, and for many applications being able to handle transactions across multiple resources isn't a requirement.

 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Adeel...

Thanks for your reply..

in that example, we can use Annotation @Transactional..
i have modified my application's configuration..
and shown like the following code :


is it configuration true?..
iam using sessionFactory and transaction manager..

and the DAO code is like this :


is it DAO have been configured as Transactional mode?..

iam sorry before.. iam still confusing about the rollBackFor Property..
i've been configure Transactional Annotation like this one :
@Transactional(readOnly=false,rollbackFor=Exception.class)

is it the rollback will executed if any errors occured?..
i just use rollbackFor=Exception.class, and not use specify another Exception classes, beacuse all of the Exception classes is inheritated of "java.lang.Exception"..

Thank's in advance
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need not define DataSourceTransactionManager, if you are using Hibernate, or you can think the other way around.

Well, if you define general Exception class, then it means you want to rollback the particular transaction in case any exception occurs. There are cases when you still want to commit the transaction if one kind of exceptions occur and rollback the transaction when the other kind of exceptions occur. I hope it made it clear now.
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Adeel for your post reply..

yeah iam using hibernate..
is it enough to make transaction just use the sessionFactory Hibernate?..
The Class extends HibernateDaoSupport..
and i use the following code :


getSession().beginTransaction().begin();
getSession().beginTransaction().commit();
getSession().beginTransaction().rollback();



Thanks in advance...
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi leonardo

I am configuring hibernate in my spring project i hope you are able to configure.I have a question that you are using persistence.xml or not or there is any kind of entry in your web.xml file for your persistence.xml file.can you provide me your sample files which you use in your project just a basic one.
 
reply
    Bookmark Topic Watch Topic
  • New Topic