我有以下表模式的表:
我创建了一个在查询执行时返回值列表的方法。
protected List findAllWithGroupClause(Class clazz) {
List objects = null;
try {
startOperation();
String SQL_QUERY = "SELECT COUNT(serviceName) AS RunningInstances ,serviceName,SUM(numberofthread) as workerThread "
+ "FROM servicemanagerdetails WHERE servicemanagerstatus=:status GROUP BY serviceName";
Query query = session.createQuery(SQL_QUERY);
query.setString("status", "Running");
objects = query.list();
tx.commit();
} catch (HibernateException e) {
handleException(e);
} finally {
HibernateFactory.close(session);
}
return objects;
}
对于声明的 ServiceManagerDetails.hbm.xml 文件:
<?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">
<hibernate-mapping>
<class name="com.arosys.hibernatedatamanager.ServiceManagerDetails" table="servicemanagerdetails">
<id column="servicedetailsid" name="servicedetailsID" type="integer">
<generator class="increment"/>
</id>
<property column="serviceID" name="servicemanagerID" type="string"/>
<property column="servicemode" name="servicemode" type="string"/>
<property column="servicetype" name="servicetype" type="string"/>
<property column="servicemanagerstatus" name="servicemanagerstatus" type="string"/>
<property column="controlqueue" name="controlQueue" type="string"/>
<property column="controlexchange" name="contolExchange" type="string"/>
<property column="controlroutingkey" name="controlRoutingkey" type="string"/>
</class>
</hibernate-mapping>
我已经为此创建了列别名,它需要编写 setter 和 getter 方法以及定义映射?请解释如何从列表中检索值。
谢谢