File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Spring/Hibernate/Jboss/JTA/getCurrentSession()/createQuery is not valid without active transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Spring/Hibernate/Jboss/JTA/getCurrentSession()/createQuery is not valid without active transaction" Watch "Spring/Hibernate/Jboss/JTA/getCurrentSession()/createQuery is not valid without active transaction" New topic
Author

Spring/Hibernate/Jboss/JTA/getCurrentSession()/createQuery is not valid without active transaction

Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
I am working on JTA with Hibernate getCurrentSession(), I am using spring--> AOP transactions.

Dao class where the exception is ocurring.


I am injecting sessionFactory into Dao* implementations. When I do Code inspection on sessionFactory in AbstractCRUDDao, transactionManager is null

What are the configuration/code changes that I need to do to get this to work? Following is the error that I am getting



Following is the applicationContext.xml


Thanks,
Santosh
Seamus Minogue
Ranch Hand

Joined: Jun 24, 2008
Posts: 41
Santosh,

This is from my appContext file which works. Thought it might help you out




And then my RoleDao class extends org.springframework.orm.hibernate3.support.HibernateDaoSupport;



Other than that my context is pretty much the same as yours.


Although, now that I look at it I dont do things like



I get the session from the HibernateDaoSupport class. Take a look at the API
http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/orm/hibernate/support/HibernateDaoSupport.html


example:



Hope that helps


Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
Seamus, Thanks for your reply. I got past the above error with following configuration in my applicationContext.xml


Now I am getting following error




I did some google and made the following changes to configurations but still it does not work as of now.




Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
Seamus, Is your DAO handling transactions at method level using HibernateTemplate? Can you please post your DAO code if you can?
Seamus Minogue
Ranch Hand

Joined: Jun 24, 2008
Posts: 41
Santosh,

Actually transaction handling is being done at the service level. The reason being:

My service may call multiple DAO's and if any of them throw and error I want to rollback the transaction. Here is my DAO:




And here is the snippet from my applicationContext which does the transaction stuff:



Hope that helps.
Santosh Ramachandrula
Ranch Hand

Joined: Apr 04, 2004
Posts: 252
Following configuration worked for me(got some help from Spring forum). With Spring JTA/Jboss5.0/Hibernate3.2

Issue in my configuration was AOP decleration and I had to comment out this piece of code


Configuration that worked for me




With this
I was getting following exception
 
 
subject: Spring/Hibernate/Jboss/JTA/getCurrentSession()/createQuery is not valid without active transaction