org.hibernate.hql.ast.QuerySyntaxException [英] org.hibernate.hql.ast.QuerySyntaxException

查看:152
本文介绍了org.hibernate.hql.ast.QuerySyntaxException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行应用程序时遇到此异常,请在我的映射文件中给我一个解决方案

i get this exception when i was running an application please give me a solution

,如下所示:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="mobilserv.bo.SalesanalyzerBean" table="sales_analyzer">

        <id name="id" access="field" type="long" column="ID">
            <generator class="native" />
        </id>

        <property name="name" access="field" column="name" />
        <property name="itemname" access="field" column="itemname" />
        <property name="total_qty" access="field" column="Total_qty" />     
        <property name="amount" access="field" column="Total_amount" />

    </class>

</hibernate-mapping>

我的实体:

And my entity:

package mobilserv.bo;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Entity;


@Entity
@Table(name = "sales_analyzer")
public class SalesanalyzerBean {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;
    private String name;
    private String itemname;
    protected int total_qty;
    private double amount;

    @ManyToOne(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
    protected MenuItemBean item;

    @OneToMany(fetch=FetchType.LAZY,mappedBy = "order", cascade = CascadeType.ALL)
    protected List<OrderItemBean> orderItems;
    protected List<CategoryBean> categery;

    public List<CategoryBean> getCategery() {
        return categery;
    }
    public void setCategery(List<CategoryBean> categery) {
        this.categery = categery;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getItemname() {
        return itemname;
    }
    public void setItemname(String itemname) {
        this.itemname = itemname;
    }
    public int getTotal_qty() {
        return total_qty;
    }
    public void setTotal_qty(int total_qty) {
        this.total_qty = total_qty;
    }
    public double getAmount() {
        return amount;
    }
    public void setAmount(double amount) {
        this.amount = amount;
    }
    public MenuItemBean getItem() {
        return item;
    }
    public void setItem(MenuItemBean item) {
        this.item = item;
    }
    public List<OrderItemBean> getOrderItems() {
        return orderItems;
    }
    public void setOrderItems(List<OrderItemBean> orderItems) {
        this.orderItems = orderItems;
    }
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }


}


推荐答案

你需要展示更多内容并澄清一些事情,你目前展示的内容很混乱。

You need to show more and to clarify a few things, what you're currently showing is pretty confusing.


  1. 您正在使用 hbm.xml 映射文件和注释。他们基本上做同样的事情(提供元数据来映射实体),但它们是独占的。

  2. hbm.xml 不完整(它不会映射关联)。如果您使用它,它可能不会给出预期的结果。

  3. 显示如何创建 AnnotationConfiguration 以及如何在 hibernate.cfg.xml中声明 SalesanalyzerBean

  4. 您遇到的异常说HQL查询在语法上不正确。 提供HQL查询。

  1. You're using both an hbm.xml mapping file and annotations. They're basically doing the same thing (providing metadata to map an entity) but they're exclusive. Use one or the other, not both together.
  2. The hbm.xml is incomplete (it doesn't map the associations). If you're using it, it might not give the expected results.
  3. It might actually be interesting to show how you create the AnnotationConfiguration and how your SalesanalyzerBean is declared in your hibernate.cfg.xml
  4. The exception you're facing says a HQL query is syntactically incorrect. Provide the HQL query.

这篇关于org.hibernate.hql.ast.QuerySyntaxException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆