Java Reference
In-Depth Information
<prop key="java.naming.provider.url">
jnp://localhost:1099
</prop>
<prop key="java.naming.factory.url.pkgs">
org.jboss.naming.client
</prop>
</props>
</property>
</bean>
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>policydetail.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect= org.hibernate.dialect.Oracle9Dialect
</value>
</property>
</bean>
</beans>
LocalSessionFactoryBean
is a factory bean that creates a Hibernate
SessionFactory
from the supplied configuration parameters and data source object. Note that Hibernate
ORM knows all about the
PolicyDetail
POJO from the mapping resource
policydetail.
hbm.xml
. Since I intend to support Oracle Database for now, I have configured
Oracle9Dialect
. Thus, switching to another database is just a matter of configuration.
You will need to change your data source configuration and the dialect used by
SessionFactory
.
It is not advisable to directly expose the ORM persistence API to the business tier
objects. I will use the DAO to wrap the underlying ORM access. Spring ORM provides the
convenience base class
HibernateDaoSupport
just for this purpose. Listing 5-16 shows the
modified
PolicyDetailDaoImpl
from Listing 5-12.
