当前位置: 代码迷 >> J2EE >> 大神指导HQL语句
  详细解决方案

大神指导HQL语句

热度:80   发布时间:2016-04-19 22:39:47.0
大神指点HQL语句!

public List<CarTurn> listCarTrun(String from,
String to) {           
   String hql = "from CarTurn c where c.delFlag='N'";
if (null != from) {
hql += " and c.startStation.stationName like '%" + from + "%'";
}
if (null != to) {
hql += " and c.destinationStation.stationName like '%" + from
+ "%'";
}
Query query = getSession().createQuery(hql);
return query.list();


CarTrun类部分属性:

@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="start_station_id")
private Station startStation;   //出发站

@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="destination_station_id")
private Station destinationStation;  //终点站

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token:  and near line 1, column 55 [from com.swu.kysp.domain.CarTurn c where c.delFlag='N' and c.startStation.stationName like '%%' and c.destinationStation.stationName like '%%']

------解决方案--------------------
'%%' and   这个引号和and中间是不是空格有点多。你修改一下试试。
  相关解决方案