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=?  这个地方 没有值,只有问号,所以引起了无效的描述符索引。
要怎么解决啊有人遇到过这种情况吗?

解决方案 »

  1.   

    where articleses0_.userid=?];  
    删除
      

  2.   

    where articleses0_.userid=?];   
    那一句是Hibenate自动生成的,我干预不了
      

  3.   

    我错了,应该是前面的articleses0_.userid as userid1_, articleses0_.id as id1_,和后面的articleses0_.id as id0_0_, articleses0_.userid as userid0_0_, 重复了,但是这些语句是自动生成的,怎么回事
      

  4.   

    报的是你的hql 语句问题!
      

  5.   

    补充:hql的输出语句如下
    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天了,难道这个问题要搞死我泪奔
      

  6.   

    大家好,我楼主,今天是我研究这个问题的第4天了,记得2天前我去图书馆借了3本hibernate的书,把他们都搞透了,都还没找到原因。我走到了这一步,确信自己的代码没问题,然后我居然把目光投向了Microsoft的驱动。这样我离真正的答案已经很近了,百度一搜,原来很多人都遇到过我的问题,不过都没人找到答案。
        不用多久,我在网上找到了一篇文章《浅谈如何解决微软自带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分