JPA - 不区分大小写的ORDER BY子句

时间:2015-01-19 13:10:12

标签: java jpa case jpql

我在JPA中需要一个不敏感的ORDER BY子句。不知怎的,它不起作用。我尝试了几种方法,从nslsort到lower(fieldname),没有任何作用,因为我总是得到同样的错误:"期待IDENTIFIER,找到' lower'",这意味着我可以' ; t使用ORDER BY后面的实际字段名称。

但必须有办法使这项工作。它需要与一些WHERE子句一起使用,具体取决于用户输入。


@Neil Stockholm: 这不是我使用的查询的示例。我刚才解释说我尝试了nlssort和其他各种函数的选项,包括lower()和upper()函数。这是我到目前为止尝试过的一个例子(o.ACTIVITY_NAME是一个java.lang.String):

SELECT o, LOWER(o.ACTIVITY_NAME) as NAME_ORDER FROM Dbrd o ORDER BY ORDER_NAME asc

这会引发错误:

java.lang.IllegalArgumentException: line 1: unexpected token: LOWER

我接下来尝试的是以下内容:

SELECT o FROM Dbrd o ORDER BY LOWER(o.ACTIVITY_NAME) asc

这会引发以下错误:

java.lang.IllegalArgumentException: line 1: expecting IDENTIFIER, found 'lower'

我希望这可以帮助你和所有其他人在这里帮助我解决这个问题。不幸的是,我真的不知道该尝试什么。到目前为止一切都失败了。


Dbrd课程:

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;

import javax.persistence.*;
@NamedQueries({
    @NamedQuery(name="getDbrdData", query="SELECT o FROM Dbrd o")
})

/**
 * @author t.kuess
 *
 */
@Entity
@Table(name = "KORE_RU_DBRD_VIEW")
public class Dbrd implements Serializable {

    private static final long serialVersionUID = 1L;

    public Dbrd() {
        super();
    }

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

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

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

    @Column(name = "ORDER_ID")
    private BigInteger ORDER_ID;

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

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

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

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

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

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

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

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

    @Column(name = "ACTIVITY_AMOUNT_DEF_CURR")
    private BigDecimal ACTIVITY_AMOUNT_DEF_CURR;

    @Column(name = "ACTIVITY_AMOUNT")
    private BigDecimal ACTIVITY_AMOUNT;

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

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

    @Column(name = "PAYMENT_DATE_SAP")
    @Temporal(TemporalType.DATE)
    private Date PAYMENT_DATE_SAP;

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

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

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

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

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

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

    @Column(name = "ORDER_AMOUNT_DEF_CUR")
    private BigDecimal ORDER_AMOUNT_DEF_CUR;

    @Column(name = "ORDER_AMOUNT")
    private BigDecimal ORDER_AMOUNT;

注意:我没有发布所有的getter和setter。它们存在,它们是从您在上面看到的字段中生成的。

0 个答案:

没有答案