Java Reference
In-Depth Information
Because filters do not use any database-specific functionality beyond the Hibernate config-
uration, you should not encounter any difficulty running this example on databases other than
HSQLDB. The Hibernate configuration file defines the database configuration and connection
information, along with the XML mapping document for the User class (see Listing 11-4).
Listing 11-4. The Hibernate XML Configuration File for the Example
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
org.hsqldb.jdbcDriver
</property>
<property name="hibernate.connection.url">
jdbc:hsqldb:file:filterdb;SHUTDOWN=true
</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">0</property>
<property name="dialect">
org.hibernate.dialect.HSQLDialect
</property>
<!-- Mapping files -->
<mapping resource="com/hibernatebook/filters/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The source code for this chapter includes the schema we used for the HSQL database to
create the table for the filterdb database.
Summary
Filters are a useful way to separate some database concerns from the rest of your code. A set
of filters can cut back on the complexity of the HQL queries used in the rest of your applica-
tion, at the expense of some runtime flexibility. Instead of using views (which must be created
at the database level), your applications can take advantage of dynamic filters that can be acti-
vated as and when they are required.
Search WWH ::




Custom Search