This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 3 and Hibernate 4 Configuration Question" Watch "Spring 3 and Hibernate 4 Configuration Question" New topic
Author

Spring 3 and Hibernate 4 Configuration Question

David Ratliff
Greenhorn

Joined: Jul 09, 2009
Posts: 8
Hello,

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,

Dave
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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().

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1632
    
    7

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



nice article on it here
http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/

If you need CGLIB is it on the classpath?


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

Joined: Mar 07, 2010
Posts: 1632
    
    7

Edit - nvm I missed the <tx:annotation-driven transaction-manager="transactionManager" /> in your config I thought it was missing.
 
Don't get me started about those stupid light bulbs.
 
subject: Spring 3 and Hibernate 4 Configuration Question
 
Similar Threads
Injection Problem
Migrating from Spring 2.0 and Hibernate 3.0 to Spring 3.1 and Hibernate 4.1
how to get session from spring-config.xml
tell me what is this error?
HibernateDaoSupport and Transaction