简单的现实,没用到DAOFactorypublic interface DaoImpl {

public void add(Object obj) throws DaoException;
public void update(Object obj) throws DaoException;
public void remove(Class cla, String id) throws DaoException;
public Object findId(Class cla, String id) throws DaoException;
public List findList(Object obj, PageBean page) throws DaoException;
public List findList(Object obj, PageBean page, Object order) throws DaoException;
public int count(Object obj) throws DaoException;}public interface NewsTypeDao extends DaoImpl{

public void remove(String id) throws DaoException;
public NewsType findId(String id) throws DaoException;}public interface NewsDao extends DaoImpl { public void remove(String id) throws DaoException;
public News findId(String id) throws DaoException;}public class HibernateBaseDao implements DaoImpl {
  //实现DaoImpl
}//实现NewsTypeDao
public class NewsTypeDaoHibernate extends HibernateBaseDao implements NewsTypeDao { public void remove(String id) throws DaoException {
remove(NewsType.class, id);
} public NewsType findId(String id) throws DaoException {
return (NewsType)findId(NewsType.class, id);
}}//实现NewsDao
public class NewsDaoHibernate extends HibernateBaseDao implements NewsDao { public void remove(String id) throws DaoException {
remove(News.class, id);
} public News findId(String id) throws DaoException {
return (News) findId(News.class, id);
}
}

解决方案 »

  1.   

    news {  private String newsId;  //id为字符型
      private NewsType newsType;}调用如下
    NewsTypeDao newstypeDao = new NewsTypeDaoHibernate();
    NewsType newsType = newsTypeDao.findId("1001");
    News news = new News();
    news.setNewsType(newsType);
    NewsDao newsDao = new NewsDaoHibernate();
    List list = newsDao.findList(news, null, null); //返回newsTypeId = 1001的所有记录代码还很拙劣,有待改进
      

  2.   

    这个在项目中我是这么写的....楼主有兴趣的话可以短信我交换代码看看 * DBSearcher提供了对象化的查询接口 通过传递ResultFilter类参数来获得相应的查询结果;
     * 范例:
     * ResultFilter rf = ForumResultFilter.createDefaultThreadFilter();
     * rf.appendSearchCondition("forumid=" + forumId);
     * forumDBSearcher.getResultList(rf);  
     * forumDBSearcher.getResultIterator(rf);
     * forumDBSearcher.getResultCount(rf);ResultFilter 还有setClass  setNumResults等等方法