I am working at a project and I want to update if from xml based configuration to annotation based. I successfully did this at service layer but having troubles with the DAO layer. I have DAO classes that extends BaseDAO, this BaseDAO extends HibernateDaoSupport. I want to annotate DAO classes with @Repository and add component scan to my context.xml. I think the problem is related to the inheritence from my DAO to the BaseDAO? this is my current code that doesn't work which explains the problem better
@Repository ("userDAO")
public class UserDAOImpl extends BaseDAO implements IUserDAO {
@Override
public Integer saveUser(UserVO user) {
user.setDateCreated(MyDateUtils.getCurrentDate());
user.setDateUpdated(MyDateUtils.getCurrentDate());
Integer userId = performSave(user);
return userId;
}
and this is my BaseDAO
public class BaseDAO extends HibernateDaoSupport {
public Integer performSave(Object object) {
Integer id = null;
try {
id = (Integer) getHibernateTemplate().save(object);
} catch (DataAccessException e) {
}
return id;
}
and this is the xml bean for the BaseDAO
<bean id="baseDAO" class="com.my.dao.database.base.BaseDAO"
abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="MyDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.showSQL}</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.my.domain.dao.UserVO</value>
</list>
</property>
</bean>
and in my context.xml i use
-- and this is the old configuration for the UserDAO (which works)
<bean id="userDAO" class="com.my.dao.database.impl.UserDAOImpl"
parent="baseDAO" />
so to be clearer, i get rid of this xml bean definition for UserDAO and used the @Repository and but it stopped working and throw the java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required