日期:2014-05-19  浏览次数:20725 次

hibernate:XXX is not mapped 感觉简单的问题却解决不了??
public List<Integer> getBoxId(int boxID) {
    String sql="select distinct(loopAddr) from LampInfo where boxID =?";
    return this.getSession().createQuery(sql).setParameter(0, boxID).list();
    //return ht.find(sql, new Object[]{boxID});
}

org.hibernate.hql.ast.QuerySyntaxException: LampInfo is not mapped [select distinct(loopAddr) from LampInfo where boxID =?] 错误。
网上说错误原因:1、LampInfo 为对象名而不是表名 2、没有将LampInfo.hbm.xml加入配置文件
这两个地点都没有问题。

把sql语句修改后:
String sql="select distinct(loopAddr) from com.test.domain.LampInfo where boxID =?";
运行报java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! 错误。
网上说错误原因:1、当hql中不需要参数,而传递了参数导致,2、set参数时没有从0开始。
但此问题不属这两种。 


------解决方案--------------------
没搞懂你要做什么···
------解决方案--------------------
引用:
没搞懂你要做什么···


运行这个方法。报错了。就是看看那里错了。
------解决方案--------------------
找到错误原因了。是我项目中导入两个数据源。这个dao内引用第一个数据源。那么在这个dao内调用第二个数据源内的对象(表)。当然会出现了 LampInfo is not mapped 错误了。