Hi guys.
I am new to Hibernate and just started playing around with it yesterday. Well I have to admit it is definitely one of the best persistence solution today.
I need some help here though.
The scenario is this:
One Registrant registers for one GolfSession. One GolfSession can be registered by many registrants. I am trying to retrieve the count of Registrants that have registered for each GolfSession.
Hibernate version:
2.1
Mapping documents:
Code:
<class name="Registrant" table="Registrant">
<meta attribute="extends">BaseModel</meta>
<meta attribute="class-description">
Represents a single Registrant in the database
@author Zach Lim (with help from Hibernate)
</meta>
<id name="id" type="long" unsaved-value="null">
<generator class="identity"/>
</id>
<many-to-one name="golfSession" class="GolfSession" column="golfSession_id" />
......................
......................
</class>
<class name="GolfSession" table="GolfSession">
<meta attribute="extends">BaseModel</meta>
<meta attribute="class-description">
Represents a single GolfSession in the database.
</meta>
<id name="id" type="int" unsaved-value="null">
<generator class="identity"/>
</id>
<property name="dateString" type="string"/>
<property name="description" type="string"/>
<property name="slotsTotal" type="integer"/>
</class>
Here's the Value object below
Code:
/**
* Description of the Class
*
* @author zach
* @created April 7, 2005
*/
public class GolfSessionVO {
private GolfSession golfSession;
private Integer takenSlots;
/**
* Constructor for the GolfSessionVO object
*
* @param golfSession Description of the Parameter
* @param booked Description of the Parameter
*/
public GolfSessionVO(GolfSession golfSession, Integer takenSlots) {
this.golfSession = golfSession;
this.takenSlots = takenSlots;
}
}
My CodeI am using Spring's HibernateDaoSupport
Code:
/**
* Gets the golfSessionVO attribute of the RegistrantDAOHibernate object
*
* @return The golfSessionVO value
*/
public List getGolfSessionVO() {
return getHibernateTemplate().find(
"select GolfSessionVO(golf, count(registrant.id)) " +
"from Registrant as registrant, Golf as golf group by golf.id"
);
}
Full stack trace of any exception that occurs:
unexpected token: as ..........
I got a feeling my query is wrong. How do I do it such that I can get a List of GolfSessionVO encapsulating the GolfSession and the registration count.
I have been stuck for 1 day. Please help me guys.
Thanks.
Zach