我收到以下例外
org.springframework.orm.hibernate3.HibernateQueryException: unexpected
char: '{'
hibernateTemplate.find("select new com.XXX.application.modules.service.vo.ServiceRuleVO( A.id, A.serviceTypeId, A.petLocationId, A.startDate, A.endDate, A.status, A.recurFrequency, A.recurCount, A.recurInterval, A.recurByDays, A.recurByMonths, A.recurByMonthDay, A.billable, A.modifiedBy, A.modifiedTime, {B} ) from ServiceRule as A left join ServicePet as C on C.serviceRuleId=A.id left join Pet as B on B.id=C.petId order by FROM_UNIXTIME(A.startDate) desc");
VO Class中的构造函数
public ServiceRuleVO(int id, int serviceTypeId, int petLocationId,
int startDate, int endDate, int status, String recurFrequency,
int recurCount, int recurInterval, String recurByDays,
String recurByMonths, int recurByMonthDay, int billable,
int modifiedBy, int modifiedTime, List<Pet> petList) {
super();
this.id = id;
this.serviceTypeId = serviceTypeId;
this.petLocationId = petLocationId;
this.startDate = startDate;
this.endDate = endDate;
this.status = status;
this.recurFrequency = recurFrequency;
this.recurCount = recurCount;
this.recurInterval = recurInterval;
this.recurByDays = recurByDays;
this.recurByMonths = recurByMonths;
this.recurByMonthDay = recurByMonthDay;
this.billable = billable;
this.modifiedBy = modifiedBy;
this.modifiedTime = modifiedTime;
this.petList = petList;
}
如何使用hibernateTemplate
将数据设置为VO类答案 0 :(得分:0)
您不能像这样在查询中指定List。 HibernateQuery有一个setParameterList(String,Object [])方法。这可能会做你想要的。查看API文档:http://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/Query.html
修改强>
他是构建一个采用List参数的(更简单的)查询的示例。希望这可以指导您修改您的:
Query query = session.createQuery("from Employee e join e.skillGroups as s where s in (:skillGroups)");
// skillGroups must be a Collection type
query.setParameterList("skillGroups", skillGroups);
query.setParameter("skillGroupsLength", skillGroups.length);
List list = query.list();