legend_jhz 2008-11-13 09:53
浏览 596
已采纳

java.sql.SQLException: Column 'gp_id' not found.

在hibernate中调用存储过程,其中我的存储过程编写如下:
[code="java"]
DELIMITER $$

DROP PROCEDURE IF EXISTS qdrk.undobusiness$$

CREATE DEFINER=root@localhost PROCEDURE undobusiness()
BEGIN
DECLARE business_date timestamp default current_timestamp;
DECLARE mon int;
SELECT business_date;
SELECT max(plandate) into business_date from jz_business_plan;
SELECT business_date;
set mon = DATE_FORMAT(business_date,'%m');
WHILE (mon < DATE_FORMAT(Now(),'%m')) do
insert into jz_business_plan(g_id,gb_id,account_id,bs_id) values(g_id,gb_id,account_id,bs_id);
select g_id ,gb_id,account_id,bs_id from jz_gbmes where ((stday < date_format(Now(),'%d') and enday > date_format(Now(),'%d') and remindtype= '2') ;
set mon = mon+1;
end WHILE;
SELECT * from jz_business_plan WHERE DATE_FORMAT(jz_business_plan.plandate,'%m') = DATE_FORMAT(now(),'%m');
END$$
DELIMITER ;
[/code]
hibernate的配置文件如下:
[code="java"]
hibernate-mapping>

































{call undobusiness()}


[/code]
错误信息如下:
[code="java"]
2008-11-13 09:38:07,882 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: S0022
2008-11-13 09:38:07,882 ERROR [org.hibernate.util.JDBCExceptionReporter] - Column 'gp_id' not found.
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2148)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:111)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1655)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
at cn.qdrk.strive.dao.hibernate.CRMDaoHibernate.undoBusiness(CRMDaoHibernate.java:43)
at cn.qdrk.strive.dao.hibernate.CRMDaoHibernate$$FastClassByCGLIB$$afe1117e.invoke()
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:694)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
[/code]
[code="java"]
Caused by: java.sql.SQLException: Column 'gp_id' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1093)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2734)
at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:237)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:554)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
[/code]
[b]问题补充:[/b]
我的jz_business_plan表中有这个键值的映射啊,至于二楼说的return-property name="gp_id" column="gp_id"/>

你的属性名不是gpId吗,改成gpId一样也会出现这样的问题。

[b]问题补充:[/b]
[color=red]我调用存储过程call undobusiness();除了gp_id为4,plandate为当前时间,其他的列值都是null,难道是这方面的原因,哪么调用存储过程select g_id ,gb_id,account_id,bs_id from jz_gbmes where ((stday < date_format(Now(),'%d') and enday > date_format(Now(),'%d') and remindtype= '2') ;会列出数据,这样怎么修改呢?[/color]
[b]问题补充:[/b]
[color=red]E文没看懂,如果返回的是null,该怎么修改呢?万分感谢![/color]
[b]问题补充:[/b]
name属性是用来关联column的,我不用程序调用存储过程,在mysql命令行中调用call undobusiness();,会列出jz_business_plan的表中的内容,这张表会显示出列为:gp_id,g_id,remark,bs_id,gb_id,plandate,account_id,都会显示出来。

  • 写回答

8条回答 默认 最新

  • iteye_521 2008-11-13 10:56
    关注

    如果你的[quote]

    [/quote]
    配置的属性存储过程都返回了的话,不管是不是null因该都没关系的,英文的意思就是说[color=red]数量[/color]一定要对上,没有值的返回NULL也要把数量对上

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏