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
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