File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Spring 3 and Hibernate 4 Configuration Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 3 and Hibernate 4 Configuration Question" Watch "Spring 3 and Hibernate 4 Configuration Question" New topic

Spring 3 and Hibernate 4 Configuration Question

David Ratliff

Joined: Jul 09, 2009
Posts: 8

I am working on migrating an older project to use Spring 3 and Hibernate 4. We did use the HibernateTemplate to access the database.
Since HibernateTemplate is deprecated, I using the Session Factory directly and Hibernate Transaction Manager.
I have gone through numerous examples and everything looks good to me. But I keep getting and error when I call my method that get's the current session.

Here is the error, I don't have an stack trace that relates to this error but I can provide what it does dump.

org.hibernate.HibernateException: No Session found for current thread

My applicationConfiguration.xml

my Controller:

my DAO:

I have commented out the @Transactional because when I leave it in, c3p0 fails and my service won't even start. I know it is some configuration that I am missing or have understood incorrectly.

Please let me know if you need more information. Any help is greatly appreciated.

Thank you,

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

First you say you posted a Controller, but it doesn't look like a Controller, it looks like a Service.

Also, Hibernate requires that you have a transaction. so you have to have @Transactional somewhere

Also, you inject the transactionManager into your DAO? Why, your DAO doesn't need it.

Your xml configuration looks correct for transactionManager, sessionFactory and dataSource.

Why is C3PO pool throwing an exception? I would concern myself about that.

Please post your code for public SearchResultsType nameSearch(PersonNameType personNameRequest, Date searchFromDate){

How are you using the sessionFactory injected into your Repository? It should start with sessionFactory.getCurrentSession().



Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

I use JPA myself but if you don't have a transaction you would have to open it manually

nice article on it here

If you need CGLIB is it on the classpath?

[How To Ask Questions][Read before you PM me]
Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

Edit - nvm I missed the <tx:annotation-driven transaction-manager="transactionManager" /> in your config I thought it was missing.
I agree. Here's the link:
subject: Spring 3 and Hibernate 4 Configuration Question
It's not a secret anymore!