• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 14
Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Stas Melnychenko
Greenhorn
Posts: 14
Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
reply
    Bookmark Topic Watch Topic
  • New Topic