• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

 
Greenhorn
Posts: 14
Opera
  • Mark post as helpful
  • send pies
  • 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: 17346
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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: 17346
11
Mac IntelliJ IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
 
please buy this thing and then I get a fat cut of the action:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic