摘要:
閱讀全文
posted @
2017-09-04 16:33 David1228 閱讀(306) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-08-02 11:41 David1228 閱讀(322) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-07-24 19:10 David1228 閱讀(11392) |
評論 (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 閱讀(245) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-05-30 19:26 David1228 閱讀(3284) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2017-05-30 19:25 David1228 閱讀(1255) |
評論 (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 閱讀(2998) |
評論 (2) |
編輯 收藏
摘要:
閱讀全文
posted @
2015-12-27 16:49 David1228 閱讀(1090) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2015-10-31 12:37 David1228 閱讀(669) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2015-10-30 20:20 David1228 閱讀(2880) |
評論 (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 閱讀(23743) |
評論 (1) |
編輯 收藏
摘要:
閱讀全文
posted @
2013-11-18 18:01 David1228 閱讀(2902) |
評論 (4) |
編輯 收藏
摘要:
閱讀全文
posted @
2013-10-31 17:32 David1228 閱讀(705) |
評論 (0) |
編輯 收藏
摘要:
閱讀全文
posted @
2013-10-14 09:50 David1228 閱讀(21754) |
評論 (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 閱讀(16683) |
評論 (2) |
編輯 收藏