-1

我收到以下异常

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 类中的构造函数

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 类

4

1 回答 1

0

您不能像这样在查询中指定一个列表。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();
于 2013-09-10T13:52:32.123 回答