1

我有一个 HQL 类的 3 个表的查询。有一些一对多的关系。

我的数据库或每个实体类都没有问题..

我有一些类hibernate DAO那个查询,除了这个之外一切都很好..

jasperreport 的类 reportserviceimpl,

我有这样的错误

线程“AWT-EventQueue-0”org.hibernate.hql.ast.QuerySyntaxException 中的异常:意外令牌:ase 靠近第 1 行,第 84 列 [选择 s.product.name 作为 productName,sum(s.quantity) 作为数量,s .sales.noTable 作为 noTable,s.sales.member 作为成员,s.price 作为价格,sum(s.subtotal) 作为来自 restodeskapp.model.SalesDetail s 的 subTotal,其中 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) 在 org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258) 在 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)

这是我的 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();

这是我的销售报告

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

这里是我的销售

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
}

这是我的销售详情

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;
}

这是我的产品

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;

}

我真的不知道哪里错了..请帮忙..

谢谢你..最好的问候:)

4

2 回答 2

3

您的异常说明unexpected token: ase near line 1, column 84并且错误进一步表明您已在此处使用它->s.sales.noTable ase noTable

所以,寻找ase,你的 HBL 代码没有这个错误。我想说,在您的代码库上进行搜索,并尝试找出您在哪里指定了这个错字s.sales.noTable ase noTable。您修复s.sales.noTable ase noTable->s.sales.noTable as noTable错误应该消失。

您有可能修复了它,但仍然面临同样的错误。在这种情况下,尝试清理缓存、删除工作和临时文件夹并重复构建和部署。

看看问题是否消失。

于 2013-05-27T00:14:22.260 回答
2
    + " s.sales.noTable ase noTable,"

ase代码中不应该有错字as吗?

于 2013-05-26T22:55:36.943 回答