aspose file tools*
The moose likes Object Relational Mapping and the fly likes Trouble converting a Spring JDBC application for Spring with Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply locked New topic
Author

Trouble converting a Spring JDBC application for Spring with Hibernate

Ray Clark
Ranch Hand

Joined: Aug 16, 2012
Posts: 52
Hi, I have a Spring application working with Spring JDBC and I'm trying to convert it to use Hibernate but I can't seem to get the Spring configuration right.

My application context file has the configuration for Hibernate connecting to a MySQL database. I want to use full annotations so my beans are not defined. Here is the config file:


Here is my data access class:



If I run the code like this I get the following error on the getCurrentSession() line:
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

I've done much searching on the internet and trying various examples. I found suggestions adding the following property.
<prop key="hibernate.current_session_context_class">thread</prop>

When I do that I get the following error on the createQuery line:
createQuery is not valid without active transaction

Any suggestions as to what is wrong with my configuration?

Many Thanks,
Ray
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Please do not post the same question more than once.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble converting a Spring JDBC application for Spring with Hibernate
 
Similar Threads
No data retrieved with JBOSS
Dependency injection problem
Trouble converting a Spring JDBC app to use Spring Hibernate
Exception on Save operation with Spring annotation
HibernateDaoSupport and Transaction