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

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设置为主键啊?

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题