Articles表是Users表的外键所在的表,查Users表的时候要级联查Articles,但是就报错了List list=baseService.findAll(Users.class);
报错如下:
Hibernate operation: could not initialize a collection:
[domain.Users.articleses#3]; SQL [select articleses0_.userid as userid1_, articleses0_.id as id1_, articleses0_.id as id0_0_, articleses0_.userid as userid0_0_, articleses0_.category as category0_0_, articleses0_.title as title0_0_, articleses0_.is_recm as is5_0_0_, articleses0_.content as content0_0_ from CityOnline.dbo.Articles articleses0_ where articleses0_.userid=?];
[Microsoft][ODBC SQL Server Driver]无效的描述符索引;
nested exception is java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引主要是 userid=? 这个地方 没有值,只有问号,所以引起了无效的描述符索引。
要怎么解决啊有人遇到过这种情况吗?
报错如下:
Hibernate operation: could not initialize a collection:
[domain.Users.articleses#3]; SQL [select articleses0_.userid as userid1_, articleses0_.id as id1_, articleses0_.id as id0_0_, articleses0_.userid as userid0_0_, articleses0_.category as category0_0_, articleses0_.title as title0_0_, articleses0_.is_recm as is5_0_0_, articleses0_.content as content0_0_ from CityOnline.dbo.Articles articleses0_ where articleses0_.userid=?];
[Microsoft][ODBC SQL Server Driver]无效的描述符索引;
nested exception is java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引主要是 userid=? 这个地方 没有值,只有问号,所以引起了无效的描述符索引。
要怎么解决啊有人遇到过这种情况吗?
解决方案 »
- 在myeclipse上移除java web程序发生错误
- 求java打印数据库中的数据,从打印机中打印出来是表格形式的
- jsp file browser的中文处理问题谁解决了。
- 谁在windows环境下,配置过awstats分析weblogic日志。 我的配置总是不成功。谁有详细的配置步骤。
- <html:file/>有没有办法赋初始值?(即:随意改变file.value的内容)(在线)
- jasperreport: 为什么找不到子报表??
- struts 的传值问题
- 求助 ibatis问题!!!
- 系统一个奇怪的问题
- 进几呼救sqlserver的jdbc为什么不可用(分不够在加)(高手们看看你们不会觉得难)
- mysql 中如何按拼音字母搜索?
- tomcat6.0以上在哪下载?
删除
那一句是Hibenate自动生成的,我干预不了
Hibernate:
select
atccategor0_.id as id1_0_,
atccategor0_.name as name1_0_
from
CityOnline.dbo.AtcCategory atccategor0_
where
atccategor0_.id=?
Hibernate:
select
articleses0_.category as category1_,
articleses0_.id as id1_,
articleses0_.id as id0_0_,
articleses0_.userid as userid0_0_,
articleses0_.title as title0_0_,
articleses0_.category as category0_0_,
articleses0_.is_recm as is5_0_0_,
articleses0_.content as content0_0_
from
CityOnline.dbo.Articles articleses0_
where
articleses0_.category=?问题是:
articleses0_.category as category1_,
articleses0_.id as id1_,
articleses0_.id as id0_0_,
articleses0_.category as category0_0_,因为id和category查了两次,导致SQLException: [Microsoft][ODBC SQL Server Driver]无效的描述符索引。 但是我也不知道为什么hibernate会自动生成这样的查询语句,我都搞了3天了,难道这个问题要搞死我泪奔
不用多久,我在网上找到了一篇文章《浅谈如何解决微软自带JDBC的resultset缺陷》
内容如下:
微软自带的3个驱动包分别为:msbase.jar,mssqlserver.jar,msutil.jar 微软JDBC resultset驱动的缺点: (1)如果采用jdbc-odbc驱动,那么就必须按照查询顺序来一次读取(不论有没有image或text类型) (2)如果采用微软提供的ms sql server jdbc driver,如果查询语句中,不存在image或text类型字段,那么可以按照无序获取 (3)如果采用微软提供的ms sql server jdbc driver,如果查询语句中,存在image或text类型字段,那么就必须按照顺序读取,否则就会报告Driver]ResultSet can not re-read row data for column之类的错误因为我用了数据库源桥连接,也就是第一种(1)如果采用jdbc-odbc驱动,所以就报错了。
我用方式2连接果然就成功了。
首先,用方式2连接的话,如果通过网页访问sql2000要装sp4补丁或者1433端口已被其他软件打开。
我之前之所以用数据库源桥连接,是因为我的第一个项目要拿去教室演示,但是教室的机器没装sp4补丁,所以我就改用数据库源了桥连接,而现在的项目将来也要拿去教室演示,所以一开始我选择了方式1
我想几乎所有遇到这个问题的人都是用教学电脑的学生,要不然怎么会选方式1去连数据库呢
所以用数据库源桥连接的同学要注意了。
最后,虽然没人能给出正确答案,但是被各位的热情所感动,我决定散发了。
时间:于第4天晚上11点23分