简体   繁体   English

HQL QuerySyntaxException错误:意外令牌

[英]Error with HQL QuerySyntaxException: unexpected token

I have a query for 3 tables with HQL class. 我有3个带有HQL类的表的查询。 There are some one-to-many relationships. 有一些一对多的关系。

No problem with my database or with my entity classes for each.. 我的数据库或每个实体的实体类都没有问题。

I have some class hibernate DAO that query, all work good except this one.. 我有一些查询的休眠DAO类,除此查询外其他所有方法都很好。

class reportserviceimpl for jasperreport, jasperreport的reportserviceimpl类,

I got error like this 我有这样的错误

Exception in thread "AWT-EventQueue-0" org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ase near line 1, column 84 [select s.product.name as productName, sum(s.quantity) as quantity, s.sales.noTable ase noTable, s.sales.member as member, s.price as price, sum(s.subtotal) as subTotal from restodeskapp.model.SalesDetail s where s.sales.id = :id group by s.product.name order by s.product.name] at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31) at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24) at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59) at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:77) at org.hibernate.engine.query. 线程“ AWT-EventQueue-0”中的异常org.hibernate.hql.ast.QuerySyntaxException:意外令牌:第1行第84列附近的ase [选择s.product.name作为productName,sum(s.quantity)作为数量,s .sales.noTable ase noTable,s.sales.member作为成员,s.price作为价格,sum(s.subtotal)作为subTotal(来自restodeskapp.model.SalesDetail),其中s.sales.id =:id按s.product分组.name按s.product.name排序],位于org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24),位于org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31) org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)处的.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)在org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl .java:157)org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)org.hibernate.engine.query.HQLQueryPlan。(HQLQueryPlan.java:77)org.hibernate.engine.query 。 HQLQueryPlan.(HQLQueryPlan.java:56) HQLQueryPlan。(HQLQueryPlan.java:56)

here my code for HBL 这是我的HBL代码

List<SalesReport> salesReports =
        sessionFactory.getCurrentSession()
        .createQuery("select s.product.name as productName,"
        + " sum(s.quantity) as quantity,"
        + " s.sales.noTable as noTable,"
        + " s.sales.member as member,"
        + " s.price as price,"
        + " sum(s.subtotal) as subTotal from SalesDetail s "
        + " where s.sales.id = :id "
        + " group by s.product.name order by s.product.name")
        .setParameter("id", id)
        .setResultTransformer(
        Transformers.aliasToBean(SalesReport.class))
        .list();

here my SalesReport 这是我的销售报告

public class SalesReport {
    private String productName;
    private String member;
    private int noTable;
    private Long quantity;
    private BigDecimal subTotal;
    private BigDecimal price;
//setter getter
}

here my Sales 这是我的销售

public class Sales implements Serializable{

    @Id @GeneratedValue
    @Column(name="ID")
    private Long id;

    @Column(name="NO_TABLE", nullable=false)
    private int noTable;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="SALES_DATE",nullable=false)
    private Date salesDate;

    @OneToMany(mappedBy="sales",cascade=CascadeType.ALL)
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private List<SalesDetail> salesDetails;

    @Column(name="TOTAL_SALES",precision=18,scale=0,nullable=false)
    private BigDecimal totalSales;

    @ManyToOne
    @JoinColumn(name="Member_ID")
    private Member member;
//setter getter
}

here my salesdetail 这是我的销售细节

public class SalesDetail implements Serializable{

    @Id @GeneratedValue
    @Column(name="ID")
    private Long id;

    @ManyToOne
    @JoinColumn(name="PRODUCT_ID",nullable=false)
    private Product product;

    @Column(name="QUANTITY",nullable=false)
    private Integer quantity;

    @Column(name="PRICE",nullable=false,precision=18,scale=0)
    private BigDecimal price;

    @Column(name="SUBTOTAL",nullable=false,precision=18,scale=0)
    private BigDecimal subtotal = BigDecimal.ZERO;

    @ManyToOne
    @JoinColumn(name="SALES_ID",nullable=false)
    private Sales sales;
}

here my product 这是我的产品

public class Product implements Serializable {

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="ID")
    private Long id;
    @Column(name="NAME",unique=true,length=200)
    private String name;
    @Column(name="DESCRIPTION",unique=false,length=500)
    private String description;
    @Column(name="PRICE",unique=false,length=200)
    private BigDecimal harga;
    @Column(name="note",unique=false,length=500)
    private String note;
    @Enumerated(EnumType.STRING)
    @Column(name="STATUS",length=20)
    private EnumStatus status;
    @Enumerated(EnumType.STRING)
    @Column(name="TYPE",length=20)
    private EnumJenisMakanan type;
    @Lob
    @Column(name="PICTURE")
    private byte[] picture;

}

I realy dont know whares the wrong.. please help.. 我真的不知道鲸鱼错了..请帮助..

thanks you.. Best regard :) 谢谢..最好的问候:)

Your exception says unexpected token: ase near line 1, column 84 and the error further shows you have used it here -> s.sales.noTable ase noTable 您的异常显示unexpected token: ase near line 1, column 84 ,该错误进一步表明您已在此处使用它-> s.sales.noTable ase noTable

So, looking for ase , your HBL code doesn't have this error. 因此,寻找ase ,您的HBL代码没有此错误。 I would say, do a search on your code base and try to find out where else do you have this typo specified s.sales.noTable ase noTable . 我想说的是,在您的代码库上进行搜索,然后尝试找出您在哪里还有这种错别字指定s.sales.noTable ase noTable You fix s.sales.noTable ase noTable -> s.sales.noTable as noTable the error should go away. 您解决s.sales.noTable ase noTable - > s.sales.noTable as noTable错误应该消失。

There are chances that you fixed it but still facing the same error. 您有可能对其进行了修复,但仍然面临相同的错误。 In that condition, try to clean up your cache, delete work & temp folders and repeat a build and deploy. 在这种情况下,请尝试清理缓存,删除工作和临时文件夹并重复构建和部署。

See if the problem goes away. 查看问题是否消失。

    + " s.sales.noTable ase noTable,"

有一个在代码中的错字ase它不应该是as

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM