There is a problem with the named query
Caused by: org.hibernate.HibernateException: Errors in named queries: rentalReport
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:426)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
Rental.hbm.xml
Code:
<?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 package="com.mindtree.entity">
<class name="Rental" table="RENTAL_TABLE" dynamic-update="true"
optimistic-lock="all">
<id name="rentalId" column="RENTAL_ID" type="integer">
<generator class="increment" />
</id>
<property name="customerName" column="CUSTOMER_NAME" type="java.lang.String"/>
<property name="fromDate" column="FROM_DATE" type="date"/>
<property name="toDate" column="TO_DATE" type="date"/>
<property name="totalRent" column="TOTAL_RENT" type="java.lang.Double"/>
<property name="paymentReceived" column="PAYMENT_RECEIVED" type="java.lang.Boolean" />
<many-to-one name="vehicle" column="VEH_ID" class="Vehicle" />
</class>
<query name="rentalReport">
select rental, vehicle, vehicle.vehicleCategory, count(rental.vehicle) as rented_vehicle from rental,count(distinct vehicle.vehicleId) as total_no_vehicle from vehicle
left outer join Rental rental vehicle.vehicleId = rental.vehicle group by vehicle.vehicleCategory;
</query>
</hibernate-mapping>
Vehicle.hbm.xml
Code:
<?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 package="com.mindtree.entity">
<class name="Vehicle" table="VEHICLE_TABLE" dynamic-update="true"
optimistic-lock="all">
<id name="vehicleId" column="VEHICLE_ID" type="integer">
<generator class="increment" />
</id>
<property name="registrationNumber" column="REGISTRATION_NUMBER" unique="true" type="java.lang.String"/>
<property name="vehicleCategory" column="VEHICLE_CATEGORY" type="java.lang.String"/>
<property name="manufacturer" column="MANUFACTURER" type="java.lang.String"/>
<property name="dailyRent" column="DAILY_RENT" type="java.lang.Double"/>
<property name="mileage" column="MILEAGE" type="java.lang.Double"/>
<property name="fuel" column="FUEL_TYPE" type="java.lang.String"/>
<property name="description" column="DESCRIPTION" type="java.lang.String"/>
</class>
</hibernate-mapping>
Tables:
mysql> select * from vehicle_table;
+------------+---------------------+------------------+---------------+------------+---------+-----------+--------------
| VEHICLE_ID | REGISTRATION_NUMBER | VEHICLE_CATEGORY | MANUFACTURER | DAILY_RENT | MILEAGE | FUEL_TYPE | DESCRIPTION
+------------+---------------------+------------------+---------------+------------+---------+-----------+--------------
| 1 | TN01-AB-2009 | Car | Mahindra | 1000 | 25 | petrol | 5-seater
| 2 | AP-02-AB-2008 | Truck | Tech Mahindra | 1500 | 20 | diesel | 3-seater with
| 3 | KA-01-AB-2015 | Bus | Mahindra | 2500 | 12 | LPG | 10-seater
mysql> select * from rental_table;
+-----------+---------------+------------+------------+------------+------------------+--------
| RENTAL_ID | CUSTOMER_NAME | FROM_DATE | TO_DATE | TOTAL_RENT | PAYMENT_RECEIVED | VEH_ID
+-----------+---------------+------------+------------+------------+------------------+--------
| 1 | AAAAAA | 2016-12-10 | 2016-12-11 | 4555.55 | ? | 1
| 2 | BBBBBBB | 2016-12-10 | 2016-12-11 | 4555.55 | ? | 3
| 3 | CCCCCC | 2016-12-10 | 2016-12-11 | 4555.55 | ? | 2
| 4 | DDDDDD | 2013-01-02 | 2013-01-04 | 2000 | ? | 1
report.jsp
------------
Code:
<c:forEach items="${requestScope.rentalDetails}" var="reportObj">
<tr>
<td>
${reportObj[1].registrationNumber}
</td>
<td>
${reportObj[0].fromDate}
</td>
<td>
${reportObj[0].toDate}
</td>
<td>
${reportObj[0].customerName}
</td>
<td>
${reportObj[1].dailyRent}
</td>
<td>
${reportObj[2]}
</td>
<td>
${reportObj[3]}
</td>
<td>
${reportObj[4]}
</td>
</tr>
</c:forEach>
Expected Output:
vehicle_category | total_no_vehicle | rented_vehicle
------------------+------------------+----------------
Bus | 1 | 1
Car | 1 | 2
Truck | 1 | 1