• 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

how to inject DAO with Spring???

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am currently working of JSF with Hibernate. And i want to use Spring IOC for my DAO, so that i can avoid the multiple instances of DAO,

actually my framework is

JSF-serviceLayer -DAO(hibernate) - DB
i dont know how to configure those DAO with Spring.

please provide some information.

I want to inject those DAO.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by gopal kishan:
Hi All,

I am currently working of JSF with Hibernate. And i want to use Spring IOC for my DAO, so that i can avoid the multiple instances of DAO,

actually my framework is

JSF-serviceLayer -DAO(hibernate) - DB
i dont know how to configure those DAO with Spring.

please provide some information.

I want to inject those DAO.




Same as injecting any Java object into another:

(1) Create the DAO interface and an implementation using the technology of your choice:



(2) Create a service interface of some kind that will use the DAO:



(3) Create a service implementation that will use the DAO:



(4) Wire it into your Spring context for the service:



What's the problem? Any Spring book will show you how to do the wiring.
 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot to add the setter for the DAO on the service implementation AND I didn't have it extend the interface as needed:



My mistake. Sorry.
 
gopal kishan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

how to create spring context file.

it is like applicationcontext.xml???


I want to use spring only to inject DAO , not for other, i am directly calling hibernate session in my DAO.i am not using HibernateTemplate.

I need to use only for injection of my dao...
 
gopal kishan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI I did the same thing as u mentioned.

i created a applicationContext.xml and i placed my mappings. and i defined in serviceImpl.

when i run it shows NullPointerException?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have also the same problem.
Today only I tried using JSF/Sprng/Hibernate but when i use Dao isntance from the service implementation class i also get the Null Pointer Exception.
Below is the method from the LoginServiceImpl class:

private LoginDao loginDao;

public void setLoginDao(LoginDao loginDao)
{
this.loginDao = loginDao;
}

public User login(String username, String password) throws Exception
{
User user = null;
try
{
user = this.loginDao.getUser(username);
...................

The configuration made in the applicationContext.xml is as follows

<!-- Login DAO object: Hibernate implementation -->
<bean id="loginDao" class="com.model.dao.hibernateimpl.LoginDaoHibernateImpl">

<property name="hibernateTemplate"><ref bean="hibernateTemplate"/></property>

</bean>

<!-- User Service Defintion -->
<bean id="loginService" class="com.model.service.impl.LoginServiceImpl">
<property name="loginDao"><ref local="loginDao"/></property>
</bean>

I will be also grateful if anyone figure out where am going wrong.
[ February 02, 2006: Message edited by: Sahil Saxena ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gopal,

if you look at your applicationContext.xml, you have mentioned the class attribute="LoginDaoHibernateImpl" whereas in your LoginServiceImpl class you have a setter for LoginDao object. So, you have to make sure that the setter in your class matches the class you specified in class attribute. Hope this is helpful. Let me know if i am wrong
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gopal,

Did you find a solution? I am also facing the same issue?

Regards

Uday
 
reply
    Bookmark Topic Watch Topic
  • New Topic