• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue in annotating DAO using spring 3.0

 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • 0
  • 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







 
paul nisset
Ranch Hand
Posts: 219
  • 0
  • 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
  • 0
  • 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: 219
  • 0
  • 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
  • 0
  • 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: 219
  • 0
  • 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.




 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 205
1
Android Flex Google App Engine
  • 0
  • 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: 219
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick and painless .
Cheers.
 
Ankit Chandrawat
Ranch Hand
Posts: 88
  • 0
  • 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
  • 0
  • 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.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic