I have table with following table schema :

I have created a method that returns the list of value on query execution.
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;
}
and for that declared ServiceManagerDetails.hbm.xml file:
<?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>
i have created column alias for that it is necessary to write setter and getter method as well as define mapping?please explain how can retrieve value from list.
Thanks
You have a select statement for selecting aggregate functions COUNT, SUM etc. In this case the hibernate
Query.list()returns a list of arrays of objects.If you want to get the SUM of the fourth row, you do
and for the serviceName of the third row you do
(both examples for explaining; your code will look more variable).
You do not need to write getters and setters, you even can’t do that. You can’t use the column aliases outside the select string.