Hi,
Thanks a lot for your reply.
Here is the relevent part of my application-context.xml file:
Code:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation"
value="/WEB-INF/hibernate.cfg.xml">
</property>
</bean>
<bean id="UsersDAO" class="com.acheivers.db.UsersDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
Here is the part of my Hibernate.cfg.xml which maps to the Users table for which UsersDAO is written
Code:
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/acheivers
</property>
<property name="connection.username">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="myeclipse.connection.profile">
mysql-connector-5.0.5
</property>
<mapping class="com.acheivers.db.Users" />
</session-factory>
</hibernate-configuration>
In acheivers-servlet.xml (dispatcher servlet) i have defined this :
Code:
<bean name="jsp/login" class="com.acheivers.web.controllers.LoginController" />
In the login controller i'm using the UsersDAO like this:
Code:
UsersDAO usd = new UsersDAO();
List<Users> users = usd.findByProperty(str, str);
In the UsersDAO the above called method is defined like this:
Code:
public List findByProperty(String propertyName, Object value) {
try {
String queryString = "from Users as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
But i get a nullPointer on getHibernateTemplate() method. Why is that?? do i miss anythg???
I read that HibernateDAOSupport can create a HibernateTemplate if sessonFactory is specified. I have defined sessionFactory in application-context.xml. Is that all i need to do??
Please guide me and give an explanation. Sample codes will be much more helpful.
Thanks a lot.