legend_jhz 2008-11-12 22:23
浏览 621
已采纳

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

[color=red]在hibernate中调用存储过程,其中我的存储过程编写如下:[/color]
[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
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');
insert into jz_business_plan(g_id,gb_id,account_id,bs_id) values(g_id,gb_id,account_id,bs_id);
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]
[color=red]hibernate的配置文件如下:[/color][code="java"]
























<sql-query name="undobusiness" callable="true">










{call undobusiness()}


[/code]
[color=red]dao接口:[/color][code="java"]
public List undoBusiness() {
List list = this.getSession().getNamedQuery("undobusiness").list();
[/code]
[color=red]我的表jz_business_plan定义如下:[/color]
[code="java"]
CREATE TABLE jz_business_plan(
gp_id int(10) unsigned NOT NULL auto_increment,
g_id int(11) unsigned default NULL,
account_id int(11) unsigned default NULL,
bs_id int unsigned default null,
plandate timestamp NOT NULL default CURRENT_TIMESTAMP,
remark varchar(255) default NULL,
gb_id int unsigned default null,
index (gb_id),
FOREIGN KEY (gb_id) REFERENCES jz_guestbook (gb_id),
index (account_id),
FOREIGN KEY (account_id) REFERENCES account_table(account_id) ,
index (g_id),
FOREIGN KEY (g_id) REFERENCES jz_gbmes(g_id),
index (bs_id),
FOREIGN KEY (bs_id) REFERENCES jz_business(bs_id) ,
PRIMARY KEY (gp_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
[/code]
我调用的时候会出现java.sql.SQLException: Column 'gp_id' not found.错误,用这种方式调用其他的存储过程时没有错误,郁闷!难道我的存储过程有问题么?
错误信息如下:
[code="java"]
2008-11-13 08:33:13,382 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 0, SQLState: S0022
2008-11-13 08:33:13,382 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)
[color=red]at cn.qdrk.strive.dao.hibernate.CRMDaoHibernate$$FastClassByCGLIB$$afe1117e.invoke()[/color] at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)

[/code]
[code="java"]
[color=red]Caused by: java.sql.SQLException: Column 'gp_id' not found.[/color]
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)

[/code]

  • 写回答

1条回答 默认 最新

  • 码农戏码 2008-11-14 14:18
    关注

    你的数据库中,有没有把gp_id设置为主键啊?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波