posts - 35, comments - 0, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          hi

          Posted on 2012-09-04 10:55 timelyxyz 閱讀(152) 評論(0)  編輯  收藏
          outer-join     fetch     lazy         主鍵表class     檢索策略         檢索方式
          true/false/auto     select     false         true/false     立即檢索(n+1次查詢)     所有
          -         -     no-proxy/proxy     true         延遲檢索         所有
          -         -     -         false         立即檢索(n+1次查詢)     所有
          -         join     false         true/false     inner join         QBC,get()/load()
          -         -     -         -         立即檢索(n+1次查詢)     HQL,NativeSQL
          -         join     no-proxy/proxy     false         inner join         QBC,get()/load()
          -         -     -         -         立即檢索(n+1次查詢)     HQL,NativeSQL
          -         -     -         true         inner join         QBC,get()/load()
          -         -     -         -         延遲檢索




          String hql = "select t,count(tp) from ContentTag_Post as tp     left join fetch tp.tag as t"
              + " where tp.tag=t and t.owner.id=? "
              + " and tp.isDeleted=false and t.isDeleted=false "
              + " group by t order by t.createTime desc ";


                  String hql = "select t,count(tp) from ContentTag as t left join ContentTag_Post as tp "
                          + " where t.owner.id=? and t=tp.tag "
                          + " and t.isDeleted=false and tp.isDeleted=false "
                          + " group by t order by t.createTime desc ";

           Path expected for join!
          2012-08-22 12:47:37 [ERROR]  Invalid path: 'tp.tag'
          right-hand operand of a binary operator was null
          <AST>:0:0: unexpected end of subtree
          left-hand operand of a binary operator was null


          select查詢 join查詢

          @LazyToOne用法
          http://docs.jboss.org/hibernate/annotations/3.4/reference/zh_cn/html/entity.html
          Java中的transient,volatile和strictfp關鍵字
          http://www.iteye.com/topic/52957
          transient
            Java語言的關鍵字,用來表示一個域不是該對象串行化的一部分。當一個對象被串行化的時候,transient型變量的值不包括在串行化的表示中,然而非transient型的變量是被包括進去的


          class A implements Serializable {
           private String name;
           transient private String address;
          }

          那么你在串行化(IO流等)A類時 給它的name和address屬性賦值,那么你在提取A時,拿到了name屬性,但是卻拿不到address屬性。




          lazy是延時的意思,如果lazy=true,那么就是說數據庫中關聯子表的信息在hibernate容器啟動的時候不會加載,而是在你真正的訪問到字表非標識字段的時候,才會去加載。
          反之,如果lazy=false的話,就是說,子表的信息會同主表信息同時加載。
          一般用只有完全用到子表信息的時候,才會lazy=false

          join 查詢的時候,是用以條語句查處所有記錄,包括關聯表記錄,select查出的是N+1條記錄,兩個都是差不多的,但是如果用了lazy=true,延遲加載的話,select在查詢時只會查出主表記錄,也就是1,如果其他地方也用到了數據,此時就會自動在執行查詢,查出N,可以降低內存消耗 .還有,hibernate是的session是輕量級的,創建和銷毀都不花很多資源,查詢數據也很快,這里fetch主要起這個作用    

          Path expected for join! unexpected end of subtree

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 中超| 定南县| 巧家县| 化州市| 平阳县| 浏阳市| 乾安县| 绥棱县| 鹤山市| 吐鲁番市| 怀集县| 永仁县| 侯马市| 潜江市| 隆昌县| 肃北| 大庆市| 同心县| 荃湾区| 屯门区| 洱源县| 广水市| 柘荣县| 泰和县| 阳曲县| 兴海县| 洛浦县| 福泉市| 红原县| 休宁县| 方正县| 秦安县| 永定县| 府谷县| 石首市| 盐池县| 东丽区| 云浮市| 亚东县| 天祝| 明星|