This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring 3 and Hibernate 4 Configuration Question

 
David Ratliff
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edit - nvm I missed the <tx:annotation-driven transaction-manager="transactionManager" /> in your config I thought it was missing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic