spring+hibernate整合配置

#config/jdbc

hibernate.cfg=hibernate.cfg.xml

jdbc.server=yourServer

jdbc.port=port

jdbc.dbname=yourDBName

jdbc.username=yourUserName

jdbc.password=yourPW

jdbc.driverClassName=Driver

jdbc.url=

hibernate.dialect=

config/hibernate

<?xmlversion="1.0"?>

<!DOCTYPEhibernate-mappingPUBLIC"-//Hibernate/HibernateMappingDTD3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<classname="com.hcao.bean.Customer"table="customer">

<idname="id"type="int">

<columnname="id"/>

<generatorclass="native"/>

</id>

<propertyname="firstName"type="string">

<columnname="first_name"not-null="false"/>

</property>

<propertyname="lastName"type="string">

<columnname="last_name"not-null="false"/>

</property>

<propertyname="age"type="java.lang.Short">

<columnname="age"not-null="false"/>

</property>

<propertyname="gender"type="char">

<columnname="gender"not-null="false"/>

</property>

</class>

</hibernate-mapping>

config/hibernate/hibernate.cfg.xml

<?xmlversion="1.0"encoding="utf-8"?>

<!DOCTYPEhibernate-configurationPUBLIC

"-//Hibernate/HibernateConfigurationDTD3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<propertyname="hibernate.show_sql">false</property>

<propertyname="hibernate.dialect">org.hibernate.dialect.SybaseDialect</property>

<propertyname="hibernate.cache.use_second_level_cache">false</property>

<propertyname="hibernate.jdbc.batch_size">40</property>

<mappingresource="Facility.hbm.xml"/>

<mappingresource="Customer.hbm.xml"/>

<mappingresource="namedQueries.hbm.xml"/>

</session-factory>

</hibernate-configuration>

jdbc-context.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<beanid="placeholderConfig"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<propertyname="locations">

<list>

<value>jdbc-${instance}.properties</value>

</list>

</property>

</bean>

<!--=================configuredatasource==================-->

<beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close">

<propertyname="driverClassName"value="${jdbc.driverClassName}"/>

<propertyname="url"value="${jdbc.url}"/>

<propertyname="username"value="${jdbc.username}"/>

<propertyname="password"value="${jdbc.password}"/>

</bean>

<!--=================configureHibernate==================-->

<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<propertyname="dataSource"ref="dataSource"/>

<propertyname="configLocation"value="${hibernate.cfg}"/>

<propertyname="hibernateProperties">

<props>

<propkey="hibernate.dialect">org.hibernate.dialect.${hibernate.dialect}</prop>

</props>

</property>

</bean>

<!--===================configureDAO=========================-->

<beanid="genericDao"class="com.hcao.dao.GenericDaoImpl">

<propertyname="sessionFactory"ref="sessionFactory"/>

</bean>

<beanid="genericService"class="com.hcao.service.GenericService">

<propertyname="dao"ref="genericDao"/>

</bean>

</beans>

context.xml

<?xmlversion="1.0"encoding="UTF-8"?>

<!DOCTYPEbeansPUBLIC"-//SPRING//DTDBEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

<importresource="jdbc-context.xml"/>

<!--=========propertyplaceholderpost-processor=========-->

<beanid="placeholderConfig"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<propertyname="locations">

<list>

<value>jdbc-${instance}.properties</value>

</list>

</property>

</bean>

</beans>

相关推荐