HibernateExample\dist
prepare:
[echo] Creating required directories...
[mkdir] Created dir: C:\eclipse\workspace\HibernateExample\dist
hibernate:
[hibernatedoclet] Running <hibernate/>
[hibernatedoclet] Generating mapping file for dbdemo.Contact.
[hibernatedoclet] Generating mapping file for dbdemo.Book.
[hibernatedoclet] Generating mapping file for dbdemo.Address.
[hibernatedoclet] Generating mapping file for dbdemo.User.
BUILD SUCCESSFUL
Total time: 2 seconds
C:\eclipse\workspace\HibernateExample>
接下来然我们看看,"生成"了什么样的映射文件(*.hbm.xml):
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="dbdemo.User"
table="Users"
>
<id
name="userID"
column="LogonID"
type="string"
>
<generator class="assigned">
</generator>
</id>
<one-to-one
name="address"
class="dbdemo.Address"
cascade="none"
outer-join="auto"
constrained="false"
/>
<set
name="books"
table="Book_User_Link"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
>
<key
column="UserID"
>
</key>
<many-to-many
class="dbdemo.Book"
column="BookID"
/>
</set>
<set
name="contacts"
table="Contacts"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
>
<key
column="User_ID"
>
</key>
<one-to-many
class="dbdemo.Contact"
/>
</set>
<property
name="emailAddress"
type="string"
column="EmailAddress"
not-null="false"
unique="false"
/>
<property
name="lastLogon"
type="date"
column="LastLogon"
not-null="false"
unique="false"
/>
<property
name="password"
type="string"
column="Password"
not-null="false"
unique="false"
/>
<property
name="userName"
type="string"
column="Name"
not-null="false"
unique="false"
/>
<!--
To add non XDoclet properties, create a file named
hibernate-properties-User.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
一旦创建完映射文件(放在classpath 中,并且和对象是"一对一"关系),你就可以通过Hibernate的接口和方法来操纵系统对象。
最后说一下,本文中例子下载包中的内容,每一个单独的例子都有main方法来运行:第一个例子:HibernateDemo.java,增加两个users,并且和address相关联("一对一");第二个例子:HibernateDemoOneToMany.java,学习用Hibernate进行"一对多"映射;最后,第三个 |