'where子句'中的未知列'salepoint1_.salepoint_id'

时间:2016-08-02 16:10:07

标签: hibernate

我在Hibernate Criteria Query中遇到以下错误。

 org.hibernate.exception.SQLGrammarException: Unknown column 'salepoint1_.salepoint_id' in 'where clause'
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at com.sun.proxy.$Proxy61.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1978)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
at org.hibernate.loader.Loader.doList(Loader.java:2463)

我的实体课程如下:

<!-- language: java -->
public class SellingRate implements Serializable {

private Article article;

private SalePoint salePoint;

private int price;

private Date startDate;
private Date endDate;

public SellingRate() {
    // For Hibernate
}

public SellingRate(Article article, SalePoint salePoint, int price, Date startDate, Date endDate) {
    this.article = article;
    this.salePoint = salePoint;
    this.price = price;
    this.startDate = startDate;
    this.endDate = endDate;
}

public Article getArticle() {
    return this.article;
}

public void setArticle(Article article) {
    this.article = article;
}

public SalePoint getSalePoint() {
    return this.salePoint;
}

public void setSalePoint(SalePoint salePoint) {
    this.salePoint = salePoint;
}

public int getPrice() {
    return price;
}

public void setPrice(int price) {
    this.price = price;
}

public Date getStartDate() {
    return startDate;
}

public void setStartDate(Date startDate) {
    this.startDate = startDate;
}

public Date getEndDate() {
    return endDate;
}

public void setEndDate(Date endDate) {
    this.endDate = endDate;
}
}

我的SalePoint实体是:

<!-- language: java -->

public class SalePoint extends BaseEntity implements Serializable {

private String name;
private double latitude;
private double longitude;

public SalePoint(String name, double latitude, double longitude) {
    this.name = name;
    this.latitude = latitude;
    this.longitude = longitude;
}

public SalePoint() {
    // for hibernate
}

public long getId() {
    return super.id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public double getLatitude() {
    return latitude;
}

public void setLatitude(double latitude) {
    this.latitude = latitude;
}

public double getLongitude() {
    return longitude;
}

public void setLongitude(double longitude) {
    this.longitude = longitude;
}

public Location getLocation() {
    if(getLatitude() == 0 && getLongitude() == 0) {
        return null;
    }
    return new Location(getLatitude(), getLongitude());
}

public void setLocation(Location location) {
    setLatitude(location.getLatitude());
    setLongitude(location.getLongitude());
}
}

我的查询如下:

<!-- language: java -->
Criteria criteria = session.createCriteria(SellingRate.class)
            .add(Restrictions.ge("endDate", date))
            .add(Restrictions.le("startDate", date));
criteria.createCriteria("salePoint").add(Restrictions.eq("id", id));
return criteria.list();

我的hibernate映射是:

<!-- language: xml -->
<class name="com.restroshop.dao.model.SalePoint" table="SALEPOINT" schema="dbRestro">
    <id name="id" column="salepoint_id">
        <generator class="identity"/>
    </id>
    <property name="name" column="name"/>
    <property name="latitude" column="latitude"/>
    <property name="longitude" column="longitude"/>
    <property name="createdOn" type="java.sql.Timestamp" generated="insert" not-null="true">
        <column name="created_on" sql-type="timestamp" default="CURRENT_TIMESTAMP"/>
    </property>
    <property name="lastUpdate" type="java.sql.Timestamp" generated="always" not-null="true">
        <column name="last_update" sql-type="timestamp" default="CURRENT_TIMESTAMP"/>
    </property>
    <joined-subclass name="com.restroshop.dao.model.Restaurant" table="RESTAURANT">
        <key column="salepoint_id"/>
        <property name="address" column="address"/>
        <property name="email" column="email" unique="true"/>
        <property name="phone" column="phone"/>
        <property name="picUrl" column="pic_url"/>
    </joined-subclass>
    <joined-subclass name="com.restroshop.dao.model.Warehouse" table="WAREHOUSE">
        <key column="salepoint_id"/>
        <property name="radius" type="int"/>
    </joined-subclass>
</class>

<class name="com.restroshop.dao.model.SellingRate" table="SELLING_RATE" schema="dbRestro">
    <composite-id>
        <key-many-to-one name="article">
            <column name="article_id"/>
        </key-many-to-one>
        <key-many-to-one name="salePoint">
            <column name="salepoint_id"/>
        </key-many-to-one>
    </composite-id>
    <property name="price" column="price" type="java.lang.Integer"/>
    <property name="startDate" column="start_date" type="date" not-null="true"/>
    <property name="endDate" column="end_date" type="date" not-null="true"/>
</class>

我不确定到底出了什么问题。但我得到SQLGrammarException。请帮忙。

0 个答案:

没有答案