日期:2014-05-20 浏览次数:20742 次
package org.yh.dlogic; import java.util.ArrayList; import java.util.List; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.cfg.Configuration; public class FindCountDlogic { /** * session定义 */ private Session session =null; /** * 构造函数 */ public FindCountDlogic() { this.session =new Configuration().configure(). buildSessionFactory().openSession(); } public List findCountByID (String countId) { List countList = new ArrayList(); StringBuffer sb = new StringBuffer("from Count"); if (countId !=null && !"".equals(countId)) { sb.append(" where countid = "+countId); } String sql = sb.toString(); Query query = this.session.createQuery(sql); [color=#FF0000]countList = query.list();[/color] return countList; } }
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping package="org.yh.vo"> <class name="org.yh.vo.Count" table="count" catalog="finances"> <id name="countid" type="java.lang.String"> <column name="countid" length="25" /> <generator class="assigned"></generator> </id> <property name="type" type="java.lang.String"> <column name="type" length="2" /> </property> <property name="startMoney" type="java.lang.String"> <column name="startmoney" length="15" /> </property> <property name="remainMoney" type="java.lang.String"> <column name="remainmoney" length="15" /> </property> <property name="payMoney" type="java.lang.String"> <column name="paymoney" length="15" /> </property> <set name="moneys" inverse="true" cascade="all"> <key column = "countid"></key> <one-to-many class = "Money"/> </set> </class> </hibernate-mapping>