Java Reference
In-Depth Information
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">
org.hsqldb.jdbcDriver
</property>
<property name="connection.url">
jdbc:hsqldb:file:/spring/db/springdb;SHUTDOWN=true
</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="hibernate.connection.pool_size">0</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping class="com.hibernatebook.spring.Paper"/>
<mapping class="com.hibernatebook.spring.Article"/>
</session-factory>
</hibernate-configuration>
Spring represents the configured session factory as a LocalSessionFactoryBean . Our exam-
ple application uses annotations to manage the mappings, so we specify that the Hibernate
AnnotationConfiguration type should be used in our bean instead of the default Configuration .
n Caution Spring maintains two sets of Hibernate packages: org.springframework.orm.hibernate...
for Hibernate 2 functionality, and org.springframework.orm.hibernate3... for Hibernate 3 functional-
ity—a single-character difference. Be careful to select the correct one, as debugging the ClassNotFound
and similar exceptions that result if you use the wrong one can be extremely time-consuming!
We also specify the location and name of the configuration file relative to the classpath as
indicated by the classpath: prefix (see Listing C-3).
Listing C-3. Configuring a Session Factory Bean in Spring
<bean id="sessionFactory"
class=" org.springframework.orm.hibernate3.LocalSessionFactoryBean ">
<property name="configurationClass"
value=" org.hibernate.cfg.AnnotationConfiguration " />
<property name="configLocation"
value=" classpath:hibernate.cfg.xml " />
</bean>
As noted, our simple web application derives its database connection details from the
Hibernate configuration file. However, a larger web application typically needs to provide
database resources to other applications, in which case a Hibernate-specific configuration file
Search WWH ::




Custom Search