摘要:
閱讀全文
posted @
2017-09-04 16:33 David1228 閱讀(305) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-08-02 11:41 David1228 閱讀(320) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-07-24 19:10 David1228 閱讀(11391) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-07-19 18:10 David1228 閱讀(3433) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-06-06 23:10 David1228 閱讀(292) |
評論 (0) |
編輯 收藏
posted @
2017-06-06 23:09 David1228 閱讀(244) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-05-30 19:26 David1228 閱讀(3283) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-05-30 19:25 David1228 閱讀(1254) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2016-12-22 23:01 David1228 閱讀(4616) |
評論 (2) |
編輯 收藏
摘要:
閱讀全文
posted @
2016-11-04 23:44 David1228 閱讀(2297) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2016-07-28 17:57 David1228 閱讀(401) |
評論 (0) |
編輯 收藏
摘要: JVM調優總結 + jstat 分析jstat -gccause pid 1 每格1毫秒輸出結果jstat -gccause pid 2000 每格2秒輸出結果不斷的在屏幕打印出結果 S0 S1 E &n...
閱讀全文
posted @
2016-01-03 23:26 David1228 閱讀(2997) |
評論 (2) |
編輯 收藏
摘要:
閱讀全文
posted @
2015-12-27 16:49 David1228 閱讀(1089) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2015-10-31 12:37 David1228 閱讀(669) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2015-10-30 20:20 David1228 閱讀(2879) |
評論 (0) |
編輯 收藏
轉載文章:
http://www.qixing318.com/article/by-lua-adhesive-nginx-ecological-environment.html
posted @
2015-09-08 13:22 David1228 閱讀(512) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2015-09-08 09:34 David1228|
編輯 收藏
摘要:
閱讀全文
posted @
2015-07-29 13:48 David1228 閱讀(5555) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2014-12-03 23:56 David1228 閱讀(28338) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2013-11-19 11:48 David1228 閱讀(23742) |
評論 (1) |
編輯 收藏
摘要:
閱讀全文
posted @
2013-11-18 18:01 David1228 閱讀(2901) |
評論 (4) |
編輯 收藏
摘要:
閱讀全文
posted @
2013-10-31 17:32 David1228 閱讀(705) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2013-10-14 09:50 David1228 閱讀(21753) |
評論 (6) |
編輯 收藏
Hibernate不支持left join帶on的條件查詢。
解決辦法:使用原生SQL或者使用HQL方式需要修改hbm文件(如果項目中大部分不適用級聯配置情況下)
需求是查詢網絡信息,網絡信息中關聯了分區、網絡IP(1個網絡--N個網絡IP),網橋信息.
HQL:
public void queryVnets(Page page) {
StringBuffer hql = new StringBuffer();
hql.append("select new Map(vn.id as id, vn.vnName as vnName, b.name as vnType, ");
hql.append("vn.vnIptype as vnIptype, vn.vnIp as vnIp,vn.vnNat as vnNat, vn.vnFlag as vnFlag, ");
hql.append("vn.vnetFlag as vnetFlag, (case when sum(vmvn.state)='0' then 0 else 1 end) as vnState, ");
hql.append("vn.useType as useType, vn.createTime as createTime, ");
hql .append("zone.oneName as oneName, zone.oneHypervisor as oneHypervisor, zone.oneSeq as oneSeq) ");
hql.append("from VnetTable vn, ZoneTable zone, BridgeTable b ");
hql.append("left join fetch vn.VnTables vmvn where zone.id = vn.zoneId and vn.vnType = b.id ");
... ...
hql.append(" group by vn.id");
if (vnState != null && !"".equals(vnState)) {
if ("0".equals(vnState)) {
hql.append(" having sum(vmvn.state)=0");
} else if ("1".equals(vnState)) {
hql.append(" having sum(vmvn.state)!=0");
}
}
}
hbm配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.base.mapping.VnetTable" table="vnet_table" >
<id name="id" type="java.lang.String">
<column name="ID" length="32" />
<generator class="uuid.hex" />
</id>
<property name="vnId" type="java.lang.Long">
<column name="VN_ID">
<comment>創建虛擬網絡時得到的ID</comment>
</column>
</property>
...
<property name="zoneId" type="java.lang.String">
<column name="ZONE_ID" length="32">
<comment>分區ID</comment>
</column>
</property>
<property name="vlanId" type="java.lang.Integer">
<column name="VLAN_ID">
<comment>VLAN_ID</comment>
</column>
</property>
<set name="vnTables" lazy="false" order-by="id asc" inverse="false" fetch="join" cascade="all">
<key column="VN_NID"/>
<one-to-many class="com.base.mapping.VnTable"/>
</set>
</class>
</hibernate-mapping>
理解inverse和cascade,可以參考:http://blog.csdn.net/wkcgy/article/details/6271321
總結: <one-to-many>中,建議inverse=”true”,由“many”方來進行關聯關系的維護 <many-to-many>中,只設置其中一方inverse=”false”,或雙方都不設置 Cascade,通常情況下都不會使用。特別是刪除,一定要慎重。操作建議
一般對many-to-one和many-to-many不設置級聯,這要看業務邏輯的需要;對one-to-one和one-to-many設置級聯。 many-to-many關聯關系中,一端設置inverse=”false”,另一端設置為inverse=”true”。在one-to-many關聯關系中,設置inverse=”true”,由多端來維護關系表
posted @
2013-09-12 11:57 David1228 閱讀(16680) |
評論 (2) |
編輯 收藏
-- 以下兩個查詢效率相當,查詢時間均為0.0xx秒,~ 但是Hibernate HQL不支持from后面接子查詢,可以直接使用SQL方式解決,ibatis當然可以用了。
SELECT count(*) from (
SELECT sum(t2.STATE) as vnSum, t1.ID FROM
vnetinfo_table t1, vm_vn_table t2
where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t where t.vnSum = 0;
SELECT count(*) FROM vnetinfo_table v ,(
SELECT sum(t2.STATE) as vnSum, t1.ID as idd FROM
vnetinfo_table t1, vm_vn_table t2
where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t
where v.ID = t.idd and t.vnSum = 0;
-- 查詢效率太低了,查詢時間均為0.5xx秒左右。要比以上兩個SQL耗時很多倍。~ Hibernate支持在where后用子查詢作為查詢條件。
SELECT count(*) FROM vnetinfo_table v WHERE v.id in
(SELECT CASE WHEN SUM(t2.STATE)=0 THEN t1.ID ELSE '' END
FROM vnetinfo_table t1, vm_vn_table t2
where t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID);
-- 使用join方式替換in 查詢時間均為0.09x秒左右。明顯提高了效率,但是Hibernate HQL任然不支持在這種聯合子查詢方式。
SELECT count(*) FROM vnetinfo_table v INNER JOIN (SELECT CASE WHEN SUM(t2.STATE)=0 THEN t1.ID ELSE '' END as idd
FROM vnetinfo_table t1, vm_vn_table t2
WHERE t1.ID = t2.VN_NID and t1.ZONE_ID = '4028a49c3facdf26013fae12531b286e' GROUP BY t1.ID) t ON v.ID = t.idd and t.idd IS not NULL;
附:Mysql中關于Exists用法的介紹請參見:http://www.nowamagic.net/librarys/veda/detail/639
posted @
2013-08-21 13:47 David1228 閱讀(3757) |
評論 (2) |
編輯 收藏