sql??hql换成 from [实体类名] 试哈

解决方案 »

  1.   

    谢谢楼上,我是用的实体类名, 可能是我说的不清楚,  比如 我的hql =" from User  "  hibernate生成的就是 select ..... from user  我拿他生成的sql去数据库查询是可以查到正常的12条不同记录
      

  2.   

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
        
    <hibernate-mapping>
    <!-- 
        Created by the Middlegen Hibernate plugin 2.2    http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    --><class 
        name="model.VomAccountEatList" 
        table="vom_account_eat_list"
        lazy="false"
    >    
            <id 
                name="gameId" 
                column="game_id" 
                type="long"
                length="19"
            />
            <property 
                name="gameDatetime" 
                column="game_datetime" 
                type="java.sql.Timestamp"
                length="23"
            />
            <property 
                name="gameType" 
                column="game_type" 
                type="int"
                length="3"
            />
            <property 
                name="gameid" 
                column="gameid" 
                type="long"
                length="19"
            />
            <property 
                name="gameDate" 
                column="game_date" 
                type="java.lang.String"
                length="10"
            />
            <property 
                name="objectid" 
                column="objectid" 
                type="java.lang.String"
                length="80"
            />
            <property 
                name="gameObjectid" 
                column="game_objectid" 
                type="java.lang.String"
                length="80"
            />
            <property 
                name="eatNumber" 
                column="eat_number" 
                type="int"
                length="10"
            />
            <property 
                name="amount" 
                column="amount" 
                type="java.math.BigDecimal"
                length="18"
            />
            <property 
                name="eatAmount" 
                column="eat_amount" 
                type="java.math.BigDecimal"
                length="18"
            />
            <property 
                name="modifyDatetime" 
                column="modify_datetime" 
                type="java.sql.Timestamp"
                length="23"
            />
            <property 
                name="modifyUsername" 
                column="modify_username" 
                type="java.lang.String"
                length="23"
            />
            <property 
                name="recDatetime" 
                column="rec_datetime" 
                type="java.sql.Timestamp"
                length="23"
            />
        <!-- Associations -->
        <!-- derived association(s) for compound key -->
        <!-- end of derived association(s) -->
      </class>
    </hibernate-mapping>
      

  3.   

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
        
    <hibernate-mapping>
    <!-- 
        Created by the Middlegen Hibernate plugin 2.2    http://boss.bekk.no/boss/middlegen/
        http://www.hibernate.org/
    --><class 
        name="model.VomAccountEatList" 
        table="vom_account_eat_list"
        lazy="false"
    >    
            <id 
                name="gameId" 
                column="game_id" 
                type="long"
                length="19"
            />
            <property 
                name="gameDatetime" 
                column="game_datetime" 
                type="java.sql.Timestamp"
                length="23"
            />
            <property 
                name="gameType" 
                column="game_type" 
                type="int"
                length="3"
            />
            <property 
                name="gameid" 
                column="gameid" 
                type="long"
                length="19"
            />
            <property 
                name="gameDate" 
                column="game_date" 
                type="java.lang.String"
                length="10"
            />
            <property 
                name="objectid" 
                column="objectid" 
                type="java.lang.String"
                length="80"
            />
            <property 
                name="gameObjectid" 
                column="game_objectid" 
                type="java.lang.String"
                length="80"
            />
            <property 
                name="eatNumber" 
                column="eat_number" 
                type="int"
                length="10"
            />
            <property 
                name="amount" 
                column="amount" 
                type="java.math.BigDecimal"
                length="18"
            />
            <property 
                name="eatAmount" 
                column="eat_amount" 
                type="java.math.BigDecimal"
                length="18"
            />
            <property 
                name="modifyDatetime" 
                column="modify_datetime" 
                type="java.sql.Timestamp"
                length="23"
            />
            <property 
                name="modifyUsername" 
                column="modify_username" 
                type="java.lang.String"
                length="23"
            />
            <property 
                name="recDatetime" 
                column="rec_datetime" 
                type="java.sql.Timestamp"
                length="23"
            />
        <!-- Associations -->
        <!-- derived association(s) for compound key -->
        <!-- end of derived association(s) -->
      </class>
    </hibernate-mapping>
      

  4.   

    hql= select * from user (
    这个好像有问题吧
    hql = select from user 不要 "*"
      

  5.   

    Query query = session.createQuery(hql); 
    query.list(); 我想看看你的查询结果是怎么输出来的
    你的原因可能是list结果集中指针没有下移你可以这样试试
    Iterator it = query.list().iterator();
            while(it!=null&&it.hasNext()){
             User user = (User)it.next();
             System.out.println("user:"+user.???);
           }
      

  6.   

    你的打印语句是怎么写的?
    建议用yinyuejin的方法将数据库的记录一条一条打印出来看看
      

  7.   

    我的查询语句是没有错,可能是我写的还不够详细,        String hql = "from model.VomAccountEatList ";
            Query q = session.createQuery(hql);
            List list = q.list();//后台打印出来一条sql语句为select ....(所有列) from VomAccountEatList
     
            return list;list不是指针没有下移,确实是里面的数据都是同一条,因为我在断点跟踪(debug)的时候看过.我用后台那条sql去数据库执行是正常的,还是怀疑配置文件的问题,大家再探讨一下
      

  8.   

    对了,补充一点,VomAccountEatList 是个视图.
      

  9.   

    注From后面是接实体名而不是表名 user一般用hibernate自动生成实体类..用那个类名就好了
      

  10.   

    hql="from User"或者hql="from "+class.getClass();