spring中配置hibernate的几个要点

1.配置数据库连接
 
<bean id="DB" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName"
			value="oracle.jdbc.driver.OracleDriver">
		</property>
		<property name="url"
			value="jdbc:oracle:thin:@10.200.250.115:1521:marine">
		</property>
		<property name="username" value="marineadmin"></property>
		<property name="password" value="usoft"></property>
	</bean>

  要注意1.数据库驱动要加到build path,sqlserver用jtds,oracle用classes12.jar,或者ojdbc14.jar
        2.driverclassname,url,username,password都不能够写错,
2.配置hibernate sessionFactory

<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref bean="DB" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.OracleDialect
				</prop>
			</props>
		</property>
		<property name="mappingResources">
			<list>
				<value>hbm/GeneralQuery/QueryInfo.hbm.xml</value>
			</list>
		</property>
	</bean>


要注意的是,根据不同的数据库选择不同的dialect

你可能感兴趣的:(java,spring,oracle,Hibernate,xml)