Java 通过数据源配置属性与通过hibernateProperties配置属性
使用datasource和使用hibernateProperties有什么区别。我想在我的应用程序中使用c3P0和spring。我找到了两种方法,但我无法理解两者之间的区别 第一:Java 通过数据源配置属性与通过hibernateProperties配置属性,java,spring,hibernate,c3p0,Java,Spring,Hibernate,C3p0,使用datasource和使用hibernateProperties有什么区别。我想在我的应用程序中使用c3P0和spring。我找到了两种方法,但我无法理解两者之间的区别 第一: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" depends-on="dataSource">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
depends-on="dataSource">
<property name="dataSource" ref="dataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">false</prop>
</props>
</property>
<bean id="dataSource" destroy-method="close"
class="com.mchange.v2.c3p0.ComboPooledDataSource" >
<property name="maxPoolSize" value="10" />
<property name="numHelperThreads" value="5" />
</bean>
假的
假的
假的
第二:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
>
<property name="hibernateProperties">
<props>
<property name="hibernate.c3p0.maxSize" value="100" />
<property name="hibernate.c3p0.numHelperThreads" value="5" />>
</props>
</property>
</bean>
>
首先获得一个Spring管理的数据源,还可以将其用于JdbcTemplate或其他工作
第二个是hibernate管理的数据源,它不能被Spring重用
我强烈建议使用第一种方法,因为它还可以很容易地替换数据源进行测试(用内存中的数据库替换)或用JNDI查找替换数据源。替换第二种方法也很容易,我们只需要更改驱动程序类、url和方言。我应该选择第一种方法而不是第二种方法的任何其他原因?除非您想使用另一个连接池(C3P0有点过时),或者想要有一个灵活的本地或jndi数据源。这在使用Hibernate时不容易切换。