Posted on 2009-02-16 19:44
啥都写点 阅读(137)
评论(0) 编辑 收藏 所属分类:
J2EE
在Hibernate 3中实际上有一种机制叫做延迟加载
所谓的延迟加载就是指当程序用到数据的时候才进行加载
Hibernate中提供的delete方法最大的缺点就是必须先把数据查询出来之后 ,在进行删除,这样才能一起删除掉,最好的做法是将数据按ID进行删除àHQL
举例(各种容器的hbm文件的写法):
Set:
<hibernate-mapping>
<class
name="org.lxh.hibernate.demo01.pojo.Person"
table="person">
<id
name="id" type="java.lang.Integer">
<column
name="id" />
<generator
class="native"></generator>
</id>
<property
name="name" type="java.lang.String">
<column
name="name" length="20" />
</property>
<set
name="emails" table="emails" lazy="false">
<key
column="id"></key>
<element
type="java.lang.String"
column="address"></element>
</set>
</class>
</hibernate-mapping>
List:
<hibernate-mapping>
<class
name="org.lxh.hibernate.demo02.pojo.Person"
table="person">
<id
name="id" type="java.lang.Integer">
<column
name="id" />
<generator
class="native"></generator>
</id>
<property
name="name" type="java.lang.String">
<column
name="name" length="20" />
</property>
<list
name="books" table="books">
<key
column="id"></key>
<index
column="posit"></index>
<element
type="java.lang.String" column="title"></element>
</list>
</class>
</hibernate-mapping>
Map:
<hibernate-mapping>
<class
name="org.lxh.hibernate.demo03.pojo.Person"
table="person">
<id
name="id" type="java.lang.Integer">
<column
name="id" />
<generator
class="native"></generator>
</id>
<property
name="name" type="java.lang.String">
<column
name="name" length="20" />
</property>
<map
name="phone" table="phone">
<key
column="id"></key>
<index
type="java.lang.String" column="name"></index>
<element
type="java.lang.String"
column="numbers"></element>
</map>
</class>
</hibernate-mapping>
-- 学海无涯