81,115
社区成员
发帖
与我相关
我的任务
分享
public String yishengAll()
{
String sql="from TYisheng where del='no' and keshiId="+keshiId;
List yishengList=yishengDAO.getHibernateTemplate().find(sql);
for(int i=0;i<yishengList.size();i++)//每一个医生下的患者人数
{
TYisheng yisheng=(TYisheng)yishengList.get(i);//某一个医生
//记录该医生预约的患者人数
int count=yuyueDAO.getHibernateTemplate().find("from Tyuyue where yishengId="+yisheng.getYishengId()).size();
yisheng.setKeghAmount(count);
// int count=yuyueDAO.findAll().size();
// yisheng.setKeghAmount(count);
}
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("yishengList", yishengList);
return ActionSupport.SUCCESS;
}

我应该是这部分没有配置。
但是现在却出现了新的错误。
上网查了一下,说这种问题一般是HQL语句错误,可是我的预约表对应的实体类名就是TYuyue呀
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/model/TAdmin.hbm.xml</value>
<value>com/model/TLiuyan.hbm.xml</value>
<value>com/model/TUser.hbm.xml</value>
<value>com/model/TGonggao.hbm.xml</value>
<value>com/model/TKeshi.hbm.xml</value>
<value>com/model/TYisheng.hbm.xml</value>
<value>com/model/TYuyue.hbm.xml</value>
</list>
</property>
</bean>
这应该是DAO层注入SessionFactory的代码。
//查询该用户下的所有预约信息
public String yuyueManaMy()
{
Map session=ActionContext.getContext().getSession();
TUser user=(TUser)session.get("user");
String sql="from TYuyue where userId="+user.getUserId();
List yuyueList=yuyueDAO.getHibernateTemplate().find(sql);//findAll()
//获取每个预约单中的医生姓名
for(int i=0;i<yuyueList.size();i++)
{
TYuyue yuyue=(TYuyue)yuyueList.get(i);
String yishengName=yishengDAO.findById(yuyue.getYishengId()).getYishengName();
yuyue.setYishengName(yishengName);
}
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("yuyueList", yuyueList);
return ActionSupport.SUCCESS;
}
这个方法的yuyueDAO.getHibernateTemplate().find(sql)是可以通过的,这个功能是可以实现的。所以我很奇怪。
package com.dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.model.TYuyue;
/**
* Data access object (DAO) for domain model class TYuyue.
*
* @see com.model.TYuyue
* @author MyEclipse Persistence Tools
*/
public class TYuyueDAO extends HibernateDaoSupport
{
private static final Log log = LogFactory.getLog(TYuyueDAO.class);
// property constants
public static final String USER_ID = "userId";
public static final String YISHENG_ID = "yishengId";
public static final String SHIJIAN = "shijian";
public static final String BEIZHU = "beizhu";
protected void initDao()
{
// do nothing
}
//添加预约信息
public void save(TYuyue transientInstance)
{
log.debug("saving TYuyue instance");
try
{
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re)
{
log.error("save failed", re);
throw re;
}
}
//删除预约信息
public void delete(TYuyue persistentInstance)
{
log.debug("deleting TYuyue instance");
try
{
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re)
{
log.error("delete failed", re);
throw re;
}
}
//查询某条预约信息
public TYuyue findById(java.lang.Integer id)
{
log.debug("getting TYuyue instance with id: " + id);
try
{
TYuyue instance = (TYuyue) getHibernateTemplate().get(
"com.model.TYuyue", id);
return instance;
} catch (RuntimeException re)
{
log.error("get failed", re);
throw re;
}
}
public List findByExample(TYuyue instance)
{
log.debug("finding TYuyue instance by example");
try
{
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re)
{
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value)
{
log.debug("finding TYuyue instance with property: " + propertyName
+ ", value: " + value);
try
{
String queryString = "from TYuyue as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re)
{
log.error("find by property name failed", re);
throw re;
}
}
public List findByUserId(Object userId)
{
return findByProperty(USER_ID, userId);
}
public List findByYishengId(Object yishengId)
{
return findByProperty(YISHENG_ID, yishengId);
}
public List findByShijian(Object shijian)
{
return findByProperty(SHIJIAN, shijian);
}
public List findByBeizhu(Object beizhu)
{
return findByProperty(BEIZHU, beizhu);
}
//查询全部预约信息
public List findAll()
{
log.debug("finding all TYuyue instances");
try
{
String queryString = "from TYuyue";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re)
{
log.error("find all failed", re);
throw re;
}
}
public TYuyue merge(TYuyue detachedInstance)
{
log.debug("merging TYuyue instance");
try
{
TYuyue result = (TYuyue) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re)
{
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(TYuyue instance)
{
log.debug("attaching dirty TYuyue instance");
try
{
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re)
{
log.error("attach failed", re);
throw re;
}
}
public void attachClean(TYuyue instance)
{
log.debug("attaching clean TYuyue instance");
try
{
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re)
{
log.error("attach failed", re);
throw re;
}
}
public static TYuyueDAO getFromApplicationContext(ApplicationContext ctx)
{
return (TYuyueDAO) ctx.getBean("TYuyueDAO");
}
}


