• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Issue in annotating DAO using spring 3.0

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Spring 3.0+Hibernate in my application. This is the error I am getting while I try to annotate my DAO class.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'chatSessionBO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mercer.chat.app.dao.ChatSessionDAO com.mercer.chat.app.businessmodel.ChatSessionBO.chatSessionDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'chatSessionDAO' defined in file [D:\opt\jboss-4.0.3SP1\server\mercerhr\deploy\mercerhr.ear\mercer.war\WEB-INF\classes\com\mercer\chat\app\dao\ChatSessionDAO.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required







 
Ranch Hand
Posts: 479
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I'd look at how your components are accessng the Hibernate Session.

After brief look, it appears that retrieveSessionInfo() in ChatSessionDAO
is used by ChatSessionBO but ChatSessionDAO dosn't have a Session with it despite using a Hibernate Criteria .

That's my best guess.

-Paul
 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Paul. Any ideas how can I make sure that I get the Session ?
 
paul nisset
Ranch Hand
Posts: 479
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MercerDAO needs a HibernateTemplate to be set.
Perhaps move the HibernateTemplate in that class's excecuteFind() method to a class level private variable .
You could then set it in the Spring config file via injection.

Alternatively, if you pass in a HibernateSession via the constructor or injection ,it will create a default HibernateTemplate for you.

Check this out:

http://static.springsource.org/spring/docs/1.2.9/api/org/springframework/orm/hibernate/support/HibernateDaoSupport.html

Hope this helps,
Paul
 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just checked something out :

In our application the DAO now are being injected like this. Foe example the ServicesPageDAO, this DAO also extends MercerDAO.
So that implies, what is being done by using xml, needs to be done using annotations. I need to inject sessionFactory that is referring mySessionFactory. How do I inject this mySessionFactory using annotations.

 
paul nisset
Ranch Hand
Posts: 479
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can mix and match Annotations and injection using the config file .
I don't use annotations or @Autowired a lot so I don't know the syntax for using annotations with a Session.




 
security forum advocate
Posts: 220
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can autowire it in your ServicesDAO as follows -



 
paul nisset
Ranch Hand
Posts: 479
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick and painless .
Cheers.
 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response Sai. But when I put :


in my code as shown below


I get the following error :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'chatSessionBO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.mercer.chat.app.dao.ChatSessionDAO com.mercer.chat.app.businessmodel.ChatSessionBO.chatSessionDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'chatSessionDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.orm.hibernate3.LocalSessionFactoryBean com.mercer.chat.app.dao.ChatSessionDAO.mySessionFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.springframework.orm.hibernate3.LocalSessionFactoryBean] is defined: expected single matching bean but found 3: [&myMarsSessionFactory, &mySessionFactory, &myLogSessionFactory]
 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thanks for all the help Paul and Sai. I have been able to resolve the issue by providing a @Qualifier.

 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic