Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Stas Melnychenko
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic