我又要提问了:
现在我遇到一个难题(是难题吗? 其实不是,只是我不知道怎么解决)
现在我我的项目(struts+hibernate)中有大量的表,表中有大量的关联关系,而且这些关联关系的表数据都是很频繁的查询使用,其实刚刚开始的时候运行还是没有问题的,但是项目越做越多的时候,打开网页没有几页程序就没有办法开始往下走了,求大家一个解决方案::
(以前没有用hibernate开发过项目,问的问题很菜)
类似这样的查询很多:String queryString = "from Bedestate as model where model.jobfonda.id="+hotelid;
Query queryObjest=getSession().createQuery(queryString);
List list=queryObjest.list();
return list;

解决方案 »

  1.   

    hibernate提供了 1对1  1对多 多对一 , 多对多的支持 LZ可以查一下使用文档 如果对单表查询  还可以用Criteria
      

  2.   

    String queryString = "from Bedestate as model where model.jobfonda.id="+hotelid;
                Query queryObjest=getSession().createQuery(queryString);
                queryObjecst.setFirstResult(100);//第一条记录
                queryObjecst.setMaxResults(3);//返回记录的总条数
                List list=queryObjest.list();
                return list;
    用分页,
    如果要求更高,可以select 属性1,属性2,…………from Bedestate 但是最好不要这样做
    lazy,用延迟加载。
      

  3.   


    建议分页的朋友:
    这样是不是达到了那种目的?
    queryObj.setFirstResult(0);
    queryObj.setMaxResults(10);
    Criteria crit = sess.createCriteria(Bedestate.class);
    crit.setMaxResults(50);
    List Bedestate= crit.list();这样是否能有一定的效果??
      

  4.   


    主键表都用了lazy="false"
    外键表都用了lazy="false"
    不知道设置是否正确?
      

  5.   

    更正:外键表都用了lazy="true" 
      

  6.   

    所有的查询我都加了
    queryObj.setFirstResult(0); 
    queryObj.setMaxResults(10); 在这里面要怎么配置啊
      
     <id name="id" type="java.lang.Long">
                <column name="id" />
                <generator class="native" />
            </id>
            <many-to-one name="jobfonda" class="com.jobhotel.DAO.Jobfonda" fetch="select">
                <column name="hotelid" not-null="true" />
            </many-to-one>
      

  7.   

    所有的查询我都加了 
    queryObj.setFirstResult(0); 
    queryObj.setMaxResults(10); 在这里面要怎么配置啊 
        <class name="com.jobhotel.DAO.Bedestate" table="bedestate" lazy="true" schema="dbo" catalog="jobhotel_com_cn_final">
            <id name="id" type="java.lang.Long">
                <column name="id" />
                <generator class="native" />
            </id>
            <many-to-one name="jobfonda" class="com.jobhotel.DAO.Jobfonda" fetch="select">
                <column name="hotelid" not-null="true" />
            </many-to-one>
            <property name="boyestate" type="java.lang.Integer">
                <column name="boyestate" />
            </property>
            <property name="girlestate" type="java.lang.Integer">
                <column name="girlestate" />
            </property>
            <property name="toiletroom" type="java.lang.Integer">
                <column name="toiletroom" />
            </property>
            <property name="notoiletroom" type="java.lang.Integer">
                <column name="notoiletroom" />
            </property>
            <property name="flatlet" type="java.lang.Integer">
                <column name="flatlet" />
            </property>
            <property name="explain" type="java.lang.String">
                <column name="explain" length="500" />
            </property>
            <property name="updateTime" type="java.util.Date">
                <column name="updateTime" length="23" />
            </property>
        </class>
      

  8.   

    建议用分页 等 Session也要关闭
    在效率上也要考虑
      

  9.   

    Session我是关闭了的
    用try
    {
      ......
    }
    catch(Exception ex)
    {
      ......
    }
    finally
    {
      HibernateSessionFactory.closeSession();
            }
    是不是合适呢??建议用分页??queryObj.setFirstResult(0); 
    queryObj.setMaxResults(10); 是不是已经达到分页的目的了??
      

  10.   

    queryObj.setFirstResult(0); 
    queryObj.setMaxResults(10); 
    就是分页
      

  11.   

    报告楼上的兄弟,我是这样关闭的:
    try
    {
      ......
    }
    catch(Exception ex)
    {
      ......
    }
    finally
        {
          HibernateSessionFactory.closeSession();
        }
      

  12.   

    不是分页的问题,Session要关的。
      

  13.   

    getSession()会使内存溢出,需要配置事务进行管理
      

  14.   

    呵呵,这么多天了,还没有结贴
    Super2兄台说到正点上
    也多谢其他的朋友回答==〉》。