• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring Struts & Hibernate

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am posting this in the Spring forum because I "think" that's where this question should go.

I am new to Hibernate and Spring and am trying to incorporate into a Struts 2 application.

I have a GenericDAO

public interface GenericDAO<T, ID extends Serializable> {

public void create(T entity) throws DAOException;

public void update(T entity) throws DAOException;

public T get(ID id) throws DAOException;

public void delete(ID userId) throws DAOException;

public List<T> findAll(String queryString)
throws DAOException;
}

I have an AbstractHibernateDAO

public abstract class AbstractHibernateDAO<T, ID extends Serializable> extends HibernateDaoSupport implements GenericDAO<T, ID>{
private Class<T> persistentClass;

public AbstractHibernateDAO(){

}
/**
* Constructor that takes in a class for easy creation of DAO
*/
public AbstractHibernateDAO(Class<T> persistentClass) {
this.persistentClass = persistentClass;
}
public void create(T entity) throws DAOException {
getHibernateTemplate().save(entity);
}

public void update(T entity) throws DAOException {
getHibernateTemplate().update(entity);
}

public T get(ID id) throws DAOException {
return (T) getHibernateTemplate().get(persistentClass, id);
}

public void delete(ID id) throws DAOException {
Object record = getHibernateTemplate().load(persistentClass, id);
getHibernateTemplate().delete(record);
}

public List<T> findAll(String queryString)
throws DAOException {
return getHibernateTemplate().find(queryString);
}
}

And finally the Implementation Class

public class RefOperatorsDAOOracleImpl extends AbstractHibernateDAO {

public void create(RefOperators operator) throws DAOException {
super.create(operator);
}

public void update(RefOperators operator) throws DAOException {
super.update(operator);
}

public RefOperators get(long operatorKey) throws DAOException {
return (RefOperators) super.get(operatorKey);
}

public void delete(long operatorKey) throws DAOException {
super.delete(operatorKey);
}

public List<RefOperators> findAll()
throws DAOException {
return super.findAll("from RefOperators order by operatorKey");
}
}

The AbstractHibernateDAO constructor is requiring an instance of the Implementation Class. My question .....

is that something that gets defined in the <bean> tag of the spring application_context ???

Thanks,

Jennifer
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, here is my take. I do not like how you are holding state in your Abstract class. DAO's should never hold any state. You can do without it in my mind, and would make it much cleaner. You can still genericize it.

Also, in your Implementation class, you need to set T and ID, you are not declaring the types at all so you are even losing the generic portion of the interface and abstract class.

Persistent classes are not made as Spring Beans either, because the data in them are always changing.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic