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个回答

如果你的[quote]

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

[quote]Column 'gp_id' not found[/quote]
跟你的存储过程没啥关系,看你的关联关系配置,貌似有一个表中没有这个字段



你的属性名不是gpId吗

你单独在sqlplus中执行这个存储过程,如果也报这个问题,说明没有这个字段。如果没有问题,说明你的映射文件写的有错误。

看看这个,跟你问题很像,
[url]http://forums.hibernate.org/viewtopic.php?p=2397634&sid=964ce5a119afba90c54c2e815fb375ec[/url]

[quote]Hibernate will replace the {bss.*} expression with a list of all the columns mapped by the BssDailyStat class. Each inner query (like bss in your example) [color=red]needs to return a column for every property you've mapped in the BssDailyStat class, even if you don't care about it in this particular query[/color]. You can just return null renamed to the column in question if you like[/quote]
你的返回的东东中必须有你对存储过程返回值映射的所有属性,即便是你不需要也要返回一个null,否则在封装到JzBusinessPlan中就有问题,调试一下你的存储过程看看是否每次所有的字段都返回了东东

你的问题我也不知道为啥了,老哥还是自己在研究一下吧,以前没碰上过这种问题













1.你查出来的值能跟这些return-property的column匹配吗...
2.你的JzBusinessPlan类里面有这些return-property的name属性吗

"name属性是用来关联column的"

你看对应的对不对..然后对应的属性存不存在

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐