Frage

I'm working with Postgress and appfuse. Unfortunately, documentation is all about dao and bean but nothing when you need to call a db function.

What is the best approach to do that?

I tryed to create a DbUtil class:

public class DbUtil extends HibernateDaoSupport {

    public DbUtil() {}
    public void runCommand() {
        getHibernateTemplate().execute(new HibernateCallback() {
        @Override
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
                session.createSQLQuery("select myfunction....");
            }
        });
    }
}

and calling it from my controller:

dbUtil = new DbUtil();
dbUtil.runCommand();

give me a NullPointerException. Probably I haven't already understood the appfuse philosophy... Any help appreciated !

Thanks Bye Fred

War es hilfreich?

Lösung

You should configure your DbUtil class as a Spring bean and inject it into your class using @Autowired. That way, the Hibernate session will be set properly.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top