<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" " <hibernate-mapping package="hbm"> <class name="EmylinkUpcode" table="emylink_upcode"> <id name="id" type="integer" column="plink_code" > <generator class="org.hibernate.id.IncrementGenerator"/> </id>
<property name="account" column="account" type="string" not-null="true" length="20" /> <property name="plinkName" column="plink_name" type="string" not-null="true" length="50" /> <property name="plinkExplain" column="plink_explain" type="string" not-null="false" length="100" /> <property name="typeCode" column="type_code" type="string" not-null="false" length="8" /> <set name="emylinkUlinks" inverse="true" lazy="true" cascade="all"> <key column="plink_code"/> <one-to-many class="EmylinkUlink"/> </set>
</class> </hibernate-mapping>
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" " <hibernate-mapping package="hbm"> <class name="EmylinkUlink" table="emylink_ulink" > <id name="id" type="integer" column="id" > <generator class="org.hibernate.id.IncrementGenerator"/> </id> <property name="account" column="account" type="string" not-null="true" length="20" /> <property name="link" column="link" type="string" not-null="true" length="200" /> <property name="linkName" column="link_name" type="string" not-null="true" length="20" /> <property name="explain" column="explain" type="string" not-null="false" length="500" /> <property name="indate" column="indate" type="date" not-null="true" length="16" insert="false" //不參與插入操作 update="false" //不參與更新操作 /> <property name="sort" column="sort" type="string" not-null="false" length="3" /> <property name="private" column="private" type="string" not-null="false" length="1" /> <many-to-one name="plinkCode" column="plink_code" class="EmylinkUpcode" not-null="true" > </many-to-one> </class> </hibernate-mapping>
<hibernate-mapping package="hbm"> <class name="EmylinkUlink" table="emylink_ulink" > <id name="id" type="integer" column="id" > <generator class="org.hibernate.id.IncrementGenerator"/> </id>
<property name="account" column="account" type="string" not-null="true" length="20" /> <property name="link" column="link" type="string" not-null="true" length="200" /> <property name="linkName" column="link_name" type="string" not-null="true" length="20" /> <property name="explain" column="explain" type="string" not-null="false" length="500" /> <property name="indate" column="indate" type="date" not-null="true" length="16" insert="false" //不參與插入操作 update="false" //不參與更新操作 /> <property name="sort" column="sort" type="string" not-null="false" length="3" /> <property name="private" column="private" type="string" not-null="false" length="1" /> <many-to-one name="plinkCode" column="plink_code" class="EmylinkUpcode" not-null="true" > </many-to-one> </class> </hibernate-mapping>
* 延遲加載 如果lazy=true(延遲加載), 加載EmylinkUpcode時,hibernate不會立即加載EmylinkUlink,只有當(Iterator<EmylinkUlink> it = ul.iterator();)執行時,hibernate才加載EmylinkUlink實例; 如果在加載前就關閉session,則報異常LazyInitializationException ; 可以使用Hibernate.initialize(Object o)強制及聯加載 *J2SE5.0的泛型
emylinkUlinks集合中只能存放EmylinkUlink對象,從集合中獲取對象無需再類型轉換 struts+spring+hibernate關于hibernate中lazy="true"的問題。web.xml中用
它的原理就是:打開頁面的時候打開session,一直到頁面裝載完畢才關閉session,這樣就解決了lazy="true"時session is closed的問題。 關于OpenSessionInViewFilter 延遲加載失效問題 http://www.javaeye.com/topic/15057 OpenSessionInView的效率問題 http://www.javaeye.com/topic/17501