aspose file tools*
The moose likes Spring and the fly likes Spring, Hibernate, transaction Management | Cannot unwrap to requested type 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 » Frameworks » Spring
Bookmark "Spring, Hibernate, transaction Management | Cannot unwrap to requested type" Watch "Spring, Hibernate, transaction Management | Cannot unwrap to requested type" New topic
Author

Spring, Hibernate, transaction Management | Cannot unwrap to requested type

Stas Melnychenko
Greenhorn

Joined: Feb 20, 2012
Posts: 14

Hello. I try manage transactions with Spring.
This is my applicationContext.xml:

When I try to run my web application, I get an error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txAdvice': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager';
nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed;
nested exception
is org.hibernate.service.UnknownUnwrapTypeException: Cannot unwrap to requested type [javax.sql.DataSource]

Please help.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well, first I recommend using the @Transactional annotation in your code instead of the verbose xml style of Transaction configuration.

Also, it looks to me that it probably is in your hibernate.cfg.xml file. That it doesn't have a DataSource configured in that file.

I also recommend no longer using a hibernate.cfg.xml file and put the configuration in your Spring configuration, which includes defining a bean for your DataSource.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Stas Melnychenko
Greenhorn

Joined: Feb 20, 2012
Posts: 14

Mark Spritzler wrote:Well, first I recommend using the @Transactional annotation in your code instead of the verbose xml style of Transaction configuration.

Also, it looks to me that it probably is in your hibernate.cfg.xml file. That it doesn't have a DataSource configured in that file.

I also recommend no longer using a hibernate.cfg.xml file and put the configuration in your Spring configuration, which includes defining a bean for your DataSource.

Mark


You are right, now, when I have DataSource, apllication running well. Thanks.
One more question. What have I write to Spring configuration instead

in hibernate.cfg.xml?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6



Something like that.

I recommend looked at the Spring documentation for an example. But off the top of my head what I put is almost correct, or it might be correct. I don't memorize that stuff.

Good Luck

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring, Hibernate, transaction Management | Cannot unwrap to requested type
 
Similar Threads
Transaction doesn't rollback
Convert type fail in Spring 3.1 and Hibernate 4.1.0
Memory Issue
Cannot configure declarative transaction with hibernate and spring
Spring/Hibernate/Jboss/JTA/getCurrentSession()/createQuery is not valid without active transaction