outer-join fetch lazy 主鍵表class 檢索策略 檢索方式
true/false/auto select false true/false 立即檢索(n+1次查詢(xún)) 所有
- - no-proxy/proxy true 延遲檢索 所有
- - - false 立即檢索(n+1次查詢(xún)) 所有
- join false true/false inner join QBC,get()/load()
- - - - 立即檢索(n+1次查詢(xún)) HQL,NativeSQL
- join no-proxy/proxy false inner join QBC,get()/load()
- - - - 立即檢索(n+1次查詢(xún)) 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查詢(xún) join查詢(xún)
@LazyToOne用法
http://docs.jboss.org/hibernate/annotations/3.4/reference/zh_cn/html/entity.html
Java中的transient,volatile和strictfp關(guān)鍵字
http://www.iteye.com/topic/52957
transient
Java語(yǔ)言的關(guān)鍵字,用來(lái)表示一個(gè)域不是該對(duì)象串行化的一部分。當(dāng)一個(gè)對(duì)象被串行化的時(shí)候,transient型變量的值不包括在串行化的表示中,然而非transient型的變量是被包括進(jìn)去的
class A implements Serializable {
private String name;
transient private String address;
}
那么你在串行化(IO流等)A類(lèi)時(shí) 給它的name和address屬性賦值,那么你在提取A時(shí),拿到了name屬性,但是卻拿不到address屬性。
lazy是延時(shí)的意思,如果lazy=true,那么就是說(shuō)數(shù)據(jù)庫(kù)中關(guān)聯(lián)子表的信息在hibernate容器啟動(dòng)的時(shí)候不會(huì)加載,而是在你真正的訪問(wèn)到字表非標(biāo)識(shí)字段的時(shí)候,才會(huì)去加載。
反之,如果lazy=false的話,就是說(shuō),子表的信息會(huì)同主表信息同時(shí)加載。
一般用只有完全用到子表信息的時(shí)候,才會(huì)lazy=false
join 查詢(xún)的時(shí)候,是用以條語(yǔ)句查處所有記錄,包括關(guān)聯(lián)表記錄,select查出的是N+1條記錄,兩個(gè)都是差不多的,但是如果用了lazy=true,延遲加載的話,select在查詢(xún)時(shí)只會(huì)查出主表記錄,也就是1,如果其他地方也用到了數(shù)據(jù),此時(shí)就會(huì)自動(dòng)在執(zhí)行查詢(xún),查出N,可以降低內(nèi)存消耗 .還有,hibernate是的session是輕量級(jí)的,創(chuàng)建和銷(xiāo)毀都不花很多資源,查詢(xún)數(shù)據(jù)也很快,這里fetch主要起這個(gè)作用
Path expected for join! unexpected end of subtree
true/false/auto select false true/false 立即檢索(n+1次查詢(xún)) 所有
- - no-proxy/proxy true 延遲檢索 所有
- - - false 立即檢索(n+1次查詢(xún)) 所有
- join false true/false inner join QBC,get()/load()
- - - - 立即檢索(n+1次查詢(xún)) HQL,NativeSQL
- join no-proxy/proxy false inner join QBC,get()/load()
- - - - 立即檢索(n+1次查詢(xún)) 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查詢(xún) join查詢(xún)
@LazyToOne用法
http://docs.jboss.org/hibernate/annotations/3.4/reference/zh_cn/html/entity.html
Java中的transient,volatile和strictfp關(guān)鍵字
http://www.iteye.com/topic/52957
transient
Java語(yǔ)言的關(guān)鍵字,用來(lái)表示一個(gè)域不是該對(duì)象串行化的一部分。當(dāng)一個(gè)對(duì)象被串行化的時(shí)候,transient型變量的值不包括在串行化的表示中,然而非transient型的變量是被包括進(jìn)去的
class A implements Serializable {
private String name;
transient private String address;
}
那么你在串行化(IO流等)A類(lèi)時(shí) 給它的name和address屬性賦值,那么你在提取A時(shí),拿到了name屬性,但是卻拿不到address屬性。
lazy是延時(shí)的意思,如果lazy=true,那么就是說(shuō)數(shù)據(jù)庫(kù)中關(guān)聯(lián)子表的信息在hibernate容器啟動(dòng)的時(shí)候不會(huì)加載,而是在你真正的訪問(wèn)到字表非標(biāo)識(shí)字段的時(shí)候,才會(huì)去加載。
反之,如果lazy=false的話,就是說(shuō),子表的信息會(huì)同主表信息同時(shí)加載。
一般用只有完全用到子表信息的時(shí)候,才會(huì)lazy=false
join 查詢(xún)的時(shí)候,是用以條語(yǔ)句查處所有記錄,包括關(guān)聯(lián)表記錄,select查出的是N+1條記錄,兩個(gè)都是差不多的,但是如果用了lazy=true,延遲加載的話,select在查詢(xún)時(shí)只會(huì)查出主表記錄,也就是1,如果其他地方也用到了數(shù)據(jù),此時(shí)就會(huì)自動(dòng)在執(zhí)行查詢(xún),查出N,可以降低內(nèi)存消耗 .還有,hibernate是的session是輕量級(jí)的,創(chuàng)建和銷(xiāo)毀都不花很多資源,查詢(xún)數(shù)據(jù)也很快,這里fetch主要起這個(gè)作用
Path expected for join! unexpected end of subtree