Java Reference
In-Depth Information
<hibernate-mapping>
<class name="sample.entity.Category" table="category">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property
name="title"
column="title"
type="string"
unique="true"/>
<set name="adverts" table="link_category_advert" >
<key column="category" foreign-key="fk_advert_category"/>
<many-to-many class="sample.entity.Advert"
column="advert"
foreign-key="fk_category_advert"/>
</set>
</class>
</hibernate-mapping>
Finally, we represent the Advert class (see Listing 3-13). This class introduces the many-
to-one association, in this case with the User class. Any given advertisement must belong to a
single user, but any given user can place many different advertisements.
Listing 3-13. The Mapping of the Advert Class into the Database
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="sample.entity.Advert" table="advert">
<id name="id" type="long" column="id">
<generator class="native"/>
</id>
<property name="message" column="message" type="string"/>
<property name="title" column="title" type="string"/>
Search WWH ::




Custom Search