2012-09-10 49 views
1

如何在Spring WebFlow項目中爲此hibernate調用添加排序。我正在開發一個Spring Webflow項目,我必須在下面的調用中添加排序。如何在我的Spring WebFlow項目中爲此hibernate調用添加排序

@SuppressWarnings("unchecked") 
    public List<School_lookupModel> getSelectableSchools(String b) { 
     String myLike = b + "%"; 
     Session mySession = sessionFactory.getCurrentSession(); 
     List<School_lookupModel> mySchools = (List<School_lookupModel>) mySession 
       .createCriteria(School_lookupModel.class) 
       .add(Restrictions.like("school", myLike)).list(); 

     return mySchools; 
    } 

我tryed下面的代碼,但它不會建:

public List<School_lookupModel> getSelectableSchools(String b) { 

     String myLike = b + "%"; 

     Session mySession = sessionFactory.getCurrentSession(); 

     List<School_lookupModel> mySchools = (List<School_lookupModel>) mySession 
       .createCriteria(School_lookupModel.class) 
      .add(Restrictions.like("school", myLike) 
      .addOrder(Order.asc("school"))).list(); 


     return mySchools; 
    } 

所以有人請告訴我如何將訂單添加到第一個電話..感謝我得到以下兩個錯誤在構建:

語法錯誤,插入「)」來完成 和 方法addOrder(訂單)是未定義的類型SimpleExpression

這裏是我的課:

package org.xxx.schoolvisit.model; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Id; 
import javax.persistence.Table; 
import javax.validation.constraints.Size; 

import org.hibernate.annotations.OrderBy; 

@Entity 
@Table(name = "school") 
public class School_lookupModel { 

    @Override 
    public String toString() { 
     return "School_lookupModel [school=" + school + ", school_name=" 
       + school_name + ", region=" + region + ", district=" + district 
       + ", getSchool()=" + getSchool() + ", getSchool_name()=" 
       + getSchool_name() + ", getRegion()=" + getRegion() 
       + ", getDistrict()=" + getDistrict() + ", getClass()=" 
       + getClass() + ", hashCode()=" + hashCode() + ", toString()=" 
       + super.toString() + "]"; 
    } 

    @Id 
    @Column(name = "school") 
    private String school; 

    @Column(name = "school_name") 
    private String school_name; 

    @Column(name = "region") 
    private String region; 

    @Column(name = "district") 
    private String district; 

    public String getSchool() { 
     return school; 
    } 

    public void setSchool(String school) { 
     this.school = school; 
    } 

    public String getSchool_name() { 
     return school_name; 
    } 

    public void setSchool_name(String school_name) { 
     this.school_name = school_name; 
    } 

    public String getRegion() { 
     return region; 
    } 

    public void setRegion(String region) { 
     this.region = region; 
    } 

    public String getDistrict() { 
     return district; 
    } 

    public void setDistrict(String district) { 
     this.district = district; 
    } 


} 

回答

1

你在這個級別缺少paranthesis

.add(Restrictions.like("school", myLike) 
    .addOrder(Order.asc("Name")).list(); 

使它像這樣

.add(Restrictions.like("school", myLike) 
    .addOrder(Order.asc("Name"))).list(); 

什麼是你所得到的錯誤? 看看這裏的例子: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html 看來你的語法是正確的,它必須是O/R映射的東西,你使用註釋將類映射到表或XML文件?你有名爲Name的字段嗎?或者你有名字或NAME?你試過這些嗎?

+0

語法錯誤,插入「)」,結束 和 方法addOrder(訂單)是未定義的類型SimpleExpression –

+0

不起作用。我讓他法addOrder(訂單)是未定義的類型SimpleExpression –

相關問題