Results 1 to 7 of 7

Thread: getHibernateTemplate().load returning NullPointerException

  1. #1

    Default getHibernateTemplate().load returning NullPointerException

    I have the following:

    service class:
    Code:
    ...
    PaymentPK paymentPk  = new PaymentPK(getId1(), getId2);// This is working fine and returning the correct values
    
    Payment payment  = paymentDao.getPayment(paymentPk);//As in the Hibernate in Action examples, pg. 335
    ...
    Dao implementation class:
    Code:
    ....
    	public Payment getPayment(PaymentPK id) {
    		return (Payment)this.getHibernateTemplate().load(Payment.class, id);	
    	}     	    		        	    		
    ...
    I almost sure that I shouldn't receive a class as a parameter, but I have been following the example of the book and also did some researches but I didn't find other way out to send the parameters. Thanks.

  2. #2
    Join Date
    Mar 2007
    Posts
    515

    Default

    NPE being thrown at that line means only that hibernateTemplate is null. Check your configuration file, to see if hibernateTemplate is properly injected, if using dependency injection.

  3. #3

    Default

    It's working perfect for something like this:

    Code:
    getHibernateTemplate().find("from Payment p order by p.id")
    So, the problem is with the composite id. Can I receive I class like I did?

  4. #4

    Default

    Just a second.. let me double-check it.

  5. #5

    Default

    You are alright! The find was in other test. In the class that is generating NPE, HibernateTemplate is null. I will try fix it. Thanks.

  6. #6

    Default

    So simple, I fixed it and all is working nicely now! Thanks.

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Just out of interest, what class were you extending. If you were using HibernateDaoSupport, an exception should have been thrown if either a sessionFactory or hibernateTemplate wasn't injected.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •