sql = "select t from T1 t";表名、字段名要与对应的java文件一致;sql中不能使用“*”。

解决方案 »

  1.   

    谢谢anchor1(聪头),我的意思只是拿这个语句做个例子,用上去的SQL语句是很复杂的一句
    sql = "select Xq_Num,User_Num,Bur_num,User_name,'' as hm,Address"
    + ",'' as Dzm,Area_num,'' as Qm,Meter_dyna,'' as Bldl"
    + ",decode(meter_ratio,'01','01Q1','rr') as meter_code"
    + ",'' as Meter_code_Mis,decode(meter_ratio,'01','','rr') as meter_code1"
    + ", as Meter_code1_Mis from haequ_yhdb where "
    + "meter_ratio='01' and user_num not in (select hh from (helectro.zydnb@dbLink)) union "
    + "select Xq_Num,User_Num,Bur_num,User_name,'' as hm,Address,'' as Dzm,Area_num,'' as Qm,Meter_dyna,'' as "
    + "Bldl,decode(meter_ratio,'02','01A1','rr') as meter_code,'' as Meter_code_Mis,"
    + "decode(meter_ratio,'02','01C1','rr') as meter_code1,'' as Meter_code1_Mis "
    + "from haequ_yhdb where meter_ratio='02' and user_num not in (select hh from (helectro.zydnb@dbLink))";
    就是要执行这一句SQL,在ORAEDIT和其它数据库查询工具中都可以执行,语句本身没有任何问题。
    问题在于Hibernate执行不了语句
      

  2.   

    表名对应类名
    你的类名是小写的"haequ_yhdb"?
      

  3.   

    在映射文件中你的类名对应了某个表名,类中的成员变量对应coulumn
    如User 对应表users
    id 对应id
    userName 对应name
    ......
    那你在createQuery中用HQL语句时
    你就应该这样来用
    (select u)from User u;(select u 都可以不用写的)要查某一column: select u.userName(注意) from User u 依此类推
    要想知道进一步的,看看关于HQL语句的书,网上也可搜到``
    希望有分~~]
    呵呵 ~~
      

  4.   

    谢谢zhouzh2006()的提醒,我已经用
    session.connection().createStatement().execute(mysql);
    来执行SQL语句了,因为关系到在三个视图里操作,.hbm.xml我还没有办法映射三个视图,所以只能执行SQL的语句
      

  5.   

    晕List<Object[]> l = session.createSQLQuery(sql).list();
      

  6.   

    decode函数不知道hibernate支持不支持,得查hibernate提供的技术文档。
      

  7.   

    dreamover(梦醒了〖http://hellfire.cn〗) 兄台的这句是什么意思呢?我还不是很明白
      

  8.   

    只这么写呢
    session.createSQLQuery(sql).list();