0
votes

i using the hibernate-generic-dao framework: https://code.google.com/p/hibernate-generic-dao/. But i can not persist, or read any object. Allways i execute some method inherited from GenericDAOImpl, cause a NullPointerException.

I read some post's that says that the problem can be that I'm not setting up the sessionFactory, the framework doesn't do this? If it is the case, how implements this?

This is my interface inheriting the GenericDAO interface:

public interface EnterpriseDAO extends GenericDAO<Enterprise, String>{
}

This is my specific DAO implementation:

public class EnterpriseDAOImpl extends GenericDAOImpl<Enterprise, String>
    implements EnterpriseDAO{
}

And with this code i try to persist an object:

    EnterpriseDAO dao = new EnterpriseDAOImpl();

    Enterprise enterprise1 = new Enterprise();
    enterprise1.setUniqueId("a.0.0.0.1");
    enterprise1.setName("Empresa2");
    enterprise1.setTaxId("125-565465-564");
    enterprise1.setUserName("a.0.0.0.1");
    enterprise1.setPassword("password");

    boolean exito = dao.save(enterprise1);
    System.out.println("Se guardo: " + exito);

I hope that can help me,i dont find the way or see the error. Thank you very much!!

1

1 Answers

0
votes

Do you set the SessionFactory in your DAO ?

I'm using Spring with hibernate-generic-dao and my daos look like :

@Repository
public class EmployeeDaoImpl extends GenericDAOImpl<Employee, Long> {

    @Autowired
    @Override
    public void setSessionFactory(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }

...

}