tags:

views:

97

answers:

2

It doesn't seem to be working right now. I get a

java.lang.NullPointerException

I have a class that implements an interface

public class LearnerDao implements BaseDao {
   private BaseDao dao;
   public void setDao(BaseDao dao) {
      this.dao=dao;
   }
   .
   .
   .
}

This is my wiring

<bean id="pm" factory-bean="pmf" factory-method="getPersistenceManager"
      scope="prototype"></bean>

<bean id="learnerDao" class="com.hardwire.dao.impl.LearnerDao">
  <property name="pm" ref="pm"></property>
</bean>

<bean id="twitterUserDao" class="com.hardwire.dao.impl.TwitterUserDao">
  <property name="pm" ref="pm"></property>
</bean>

<bean id="learnerService" class="com.hardwire.service.LearnerService">
      <property name="dao" ref="learnerDao"></property
</bean>

Here's my learnerService

public class LearnerService {
private static final Logger log = 
         Logger.getLogger(LearnerService.class.getName());
private BaseDao dao;
.
    .
    .
public void insert(Learner learner){
 if (dao==null){
  log.info("dao is null");
 }
 else {
  log.info("dao is not null");
 }
 dao.insert(learner);
}
public void setDao(BaseDao dao) {
 this.dao = dao;
}

It's only learnerDao that implements BaseDao. On the other hand, bean twitterUserDao does not. I'd like to note that twitterUserDao was injected just okay but learnerDao wasn't. The logs show that learnerDao is null. So I was wondering if this had anything to do with learnerDao implementing an inteface.

A: 

Nope, you can definitely do that. Note that you're trying to set a pm property in learnerDao, but you haven't shown anything setting the dao property. Could that be the problem?

Jon Skeet
Oops sorry about that, I expounded on my post already...
Jeune
A: 

I finally found where everything's going wrong. I had this bug of code to kill in a Controller that has learnerService as its dependency:

learnerService = new LearnerService();

Laughing my ass off right now! :))

Jeune