Java Reference
In-Depth Information
I
Fetches single account
public Account getById(Integer accountId) {
Session session = this.getSession();
try {
return (Account) session.get(
Account.class, accountId);
} catch (HibernateException e) {
log.error(e);
throw new DaoException(e);
}
}
J
Fetches single account
public Account getById(Account account) {
return getById(account.getAccountId());
}
}
There is a good deal more here than in the SQL Map implementation. In the cases
where we are dealing with Account objects ( through and through ), it
is pretty simple, but things get more interesting when we start looking at returning
a List of Map objects or IdDescription objects . Because Hibernate is designed
to map a database table to a Java class, it becomes more difficult to map the same
table to different classes.
In the next example DAO implementation, we will get away from any mapping
tool, and use straight JDBC to build our DAO .
b
F
I
J
G
H
11.1.2
A JDBC DAO implementation
The last DAO implementation that we will build under this interface will use
straight JDBC . The greatest advantages that a simple JDBC -based implementation
provides are minimal configuration and increased flexibility.
Listing 11.4 shows our dao.xml configuration file.
Listing 11.4
XML fragment defining a DAO context using JDBC
<context id="jdbc">
<transactionManager type="JDBC">
<property name="DataSource"
value="SIMPLE"/>
<property name="JDBC.Driver"
value="org.postgresql.Driver" />
<property name="JDBC.ConnectionURL"
value="jdbc:postgresql:ibatisdemo" />
<property name="JDBC.Username"
value="ibatis" />
<property name="JDBC.Password"
Search WWH ::




Custom Search