类没有用Hibernate映射

时间:2015-08-13 15:07:12

标签: java hibernate orm

我有一个带有映射对象的Hibernate应用程序问题是当我执行HSQL查询时我得到了

org.springframework.orm.hibernate3.HibernateQueryException: DescargasTienda is n
ot mapped [from DescargasTienda where fecha = ? and market = ?]; nested exceptio
n is org.hibernate.hql.ast.QuerySyntaxException: DescargasTienda is not mapped [
from DescargasTienda where fecha = ? and market = ?]
        at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHiberna
teAccessException(SessionFactoryUtils.java:660)
        at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernate
AccessException(HibernateAccessor.java:412)
        at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(Hibern
ateTemplate.java:411)
        at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativ
eSession(HibernateTemplate.java:374)
        at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTe
mplate.java:912)
        at com.proximate.www.dashmate.dao.impl.DescargasTiendaDAOImpl.insert(Des
cargasTiendaDAOImpl.java:21)
        at com.proximate.www.dashmate.dao.impl.DescargasTiendaDAOImpl.insert(Des
cargasTiendaDAOImpl.java:15)

这是引发异常的代码:

@Override
public void insert(DescargasTienda o) {
    // TODO Auto-generated method stub
    if(getHibernateTemplate().find("from DescargasTienda where fecha = ? and market = ?", o.getFecha(), o.getMarket()).isEmpty()){
        getHibernateTemplate().save(o); 
    }
}

这是我的hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">update</property>
        <mapping resource="mappings/DescargasTienda.hbm.xml" /> 
    </session-factory>
</hibernate-configuration>

这是我的DescargasTienda.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 6/01/2011 05:14:47 PM by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
    <class name="com.proximate.www.dashmate.model.DescargasTienda" table="descargas_tienda">
        <id name="id" type="integer">
            <column name="id"  />
            <generator class="native" />
        </id>
        <property name="market" type="string">
            <column name="market" />
        </property>
        <property name="descargas" type="integer">
            <column name="descargas" />
        </property>
        <property name="actualizaciones" type="integer">
            <column name="actualizaciones" />
        </property>
        <property name="fecha" type="java.sql.Date">
            <column name="fecha_actualizacion" default="CURRENT_DATE"/>
        </property>
    </class>    
</hibernate-mapping>

最后这里是模特:

package com.proximate.www.dashmate.model;

public class DescargasTienda {

    private int id;
    private String market;
    private int descargas;
    private int actualizaciones;
    private int porcentaje;
    private boolean subida;

    private java.sql.Date fecha;
    public int getId() {
        return id;
    }
    public String getMarket() {
        return market;
    }
    public int getDescargas() {
        return descargas;
    }
    public int getActualizaciones() {
        return actualizaciones;
    }
    public java.sql.Date getFecha() {
        return fecha;
    }
    public void setId(int id) {
        this.id = id;
    }
    public void setMarket(String market) {
        this.market = market;
    }
    public void setDescargas(int descargas) {
        this.descargas = descargas;
    }
    public void setActualizaciones(int actualizaciones) {
        this.actualizaciones = actualizaciones;
    }
    public void setFecha(java.sql.Date fecha) {
        this.fecha = fecha;
    }

    public int getPorcentaje() {
        return porcentaje;
    }
    public boolean isSubida() {
        return subida;
    }
    public void setPorcentaje(int porcentaje) {
        this.porcentaje = porcentaje;
    }
    public void setSubida(boolean subida) {
        this.subida = subida;
    }
    @Override
    public String toString() {
        return "DescargasTienda [id=" + id + ", market=" + market
                + ", descargas=" + descargas + ", actualizaciones="
                + actualizaciones + ", porcentaje=" + porcentaje + ", subida="
                + subida + ", fecha=" + fecha + "]";
    }

}

那么在我的代码中可能出错的是我一直得到未映射的异常? 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我以某种方式设法找出问题所在。我忘了提到我有一个主项目,它依赖于另一个项目,所以如果我在我的主项目中创建一个hibernate.cfg.xml;它会覆盖项目中具有依赖项的hibernate.cfg.xml。所以在我的主项目中,我没有我的服务器说我失踪的映射:)