posts - 35, comments - 0, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

hi

Posted on 2012-09-04 10:55 timelyxyz 阅读(137) 评论(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

只有注册用户登录后才能发表评论。


网站导航: