我有这样的 Native SQL 语句:
SQL查询:
select Name ,Id,COUNT(ID) from Employee;
员工 HBM 文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="edu.model.Master" table="test_prefixmaster">
<id name="empcode" column="EMPCODE" length="10" ></id>
<property name="empname">
<column name="NAME" length="30" />
</property>
</class>
<sql-query name="SQLQuery" callable="true">
<return alias="emp" class="edu.model.Employee">
<return-property name="empid" column="EMPID" />
<return-property name="empname" column="EMPNAME" />
</return>
</sql-query>
</hibernate-mapping>
在 MyTest 类中:
Query query = session.getNamedQuery("SQLQuery");
List emp=new ArrayList();
for (int i = 0; i < emp.size(); i++) {
Employee emp = (Employee) emp.get(i);
System.out.println("Employee Id:::" + emp.getEmpId());
System.out.println("Employee Name:::" + emp.getEmpname());
//I want to get here System.out.println("Employee Count");
}
如何在循环中映射和打印员工人数?