First of all, I use MySQL 4.0.18 and the latest version of Hibernate (2.1.3)
In my java file TeamDriverVO I added an extra field points which isn't in the database table Driver, because I want to generate it at my request.
(If you made a good team, the points are different after each race :-) ).
If I use the following query, I get an exception that the column name doesn't exist. I know that this exception should be returned since points isn't a property in my driverVO.hbm.xml nor is it a column in my database table Driver. But how do I fill in this field in my Java File?
To clarify my application a bit. I want this to happen : when a user asks information on a specific Racing Team, he should see all the TeamDrivers from the Team with their points gained during all the finished races.
Query
Code:
protected static final String findTeamDriverScoresSQL =
"select teamDriver.id as {be.ngb.vo.TeamDriverVO.id}, " +
" teamDriver.driverId as {be.ngb.vo.TeamDriverVO.driver}, " +
" teamDriver.teamId as {be.ngb.vo.TeamDriverVO.team}, " +
" teamDriver.periodId as {be.ngb.vo.TeamDriverVO.period}, " +
" sum(pointsTable.points) as {be.ngb.vo.TeamDriverVO.points} " +
"from TEAMDRIVER as teamdriver" +
" inner join DRIVER as driver on teamDriver.driverid= driver.id " +
" left outer join SCORE as score on driver.id = score.driverid" +
" left outer join RACE as race on score.raceid = race.id " +
" left outer join GRADE as grade on race.gradeid = grade.id " +
" left outer join POINTSTABLE as pointsTable on grade.scoretype = pointstable.type " +
" and score.plaats = pointsTable.plaats " +
"where teamDriver.periodid = race.periodid " +
"group by teamDriver.id, teamDriver.driverId " +
"order by teamDriver.teamid ";
My Java FileCode:
public class PloegRennerVO extends AbstractVO {
protected TeamVO team;
protected DriverVO driver;
protected PeriodVO period;
protected Integer points;
/*all the getters and setters + the constructors needed for these properties */
}
My call in the DAO layerCode:
String query = findTeamDriverScoresSQL;
list = TeamImpl.getUserSession().createSQLQuery(query, "be.ngb.vo.TeamDriverVO", TeamDriverVO.class).list();
ExceptionCode:
net.sf.hibernate.QueryException: No column name found for property [points] [complete sql statement shown as above]
I've tried adding it to the mapping file as a property with a formula, but that resulted in a LazilyInitializeException. If I run this query in MySQL I get the results I would like to get in my Java File, so there should be no error there.
Thanks in advance,
Peter