Java Reference
In-Depth Information
<property name="hibernate.dialect"
value=
"net.sf.hibernate.dialect.PostgreSQLDialect" />
<property name="map.Account"
value=
"${DaoHomeRes}/hibernate/Account.hbm.xml" />
</transactionManager>
<dao interface="${DaoHome}.AccountDao"
implementation=
"${DaoHome}.hibernate.AccountDaoImpl"/>
</context>
As was discussed in chapter 10 (section 10.2.2), the HIBERNATE transaction man-
ager simply expects that the properties you would normally put in the hiber-
nate.properties file are listed as properties to the <transactionManager> element.
Because we wanted to keep our source tree clean, we did not put the Hiber-
nate mapping file for the Account bean ( Account.hbm.xml ) in the same package as
our Account bean, but instead added it to the configuration by using a map. prop-
erty that added it to our Hibernate configuration. Remember, it is all about keep-
ing the implementation of the data access separate from the interface.
Mapping the Account table
The mapping file, shown in listing 11.2, is very simple, because we map directly
from the properties files to the columns that have the same names, and there are
no related entities.
Listing 11.2
Hibernate mapping file for our Account table
<?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="org.apache.mapper2.examples.bean.Account"
table="Account">
<id name="accountId" type="int" column="accountid">
<generator class="sequence">
<param
name="sequence">account_accountid_seq</param>
</generator>
</id>
<property name="username" />
<property name="password" />
<property name="firstName" />
B
Mapping table
to a class
Hooking up sequence
for ID generation
C
Search WWH ::




Custom Search