
Originally Posted by
costin
Both HB and Spring advice against using these datasources because they do not have any pooling or any features that you would need in a production environment - they and also I suggest to use an approapriate datasource like c3p0 or Commons dbcp.
True. I deliberately opted for driver managers to remove from tests all pooling management relating issues. In production there should be pools indeed. Here's a question though. If I am using Spring only configuration then Spring provides life-cycles services to the pool including destroy-method callbacks:
Code:
<bean id="dataSource" class="&BasicDataSource;" destroy-method="close"/>
When I am using Spring+HB configuration then what? No life-cycle services? All initialization and destroy methods should be configured in hibernate.cfg.xml?

Originally Posted by
costin
You'll have no problem no matter if connection.autocommit is set to true or false.
Note that this parameter should be turned to false when using transactions otherwise the information will always hit the database even when the transaction is not commited yet.
Actually I have a problem. In Spring+HB config with autocommit=false (which is definitely is the most appropriate option) I have to wrap my target into transactional proxy.Otherwise nothing sticks with database (actually, it's the way it's supposed to be). So my configuration looks like this.
Code:
<beans>
<bean id="sessionFactory" class="&LocalSessionFactoryBean;">
<property name="configLocation"
value="classpath:hibernate.cfg.xml" />
</bean>
<bean id="abstractSessionFactoryHost" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="eventDao" class="&TransactionProxyFactoryBean;">
<property name="transactionManager">
<bean class="&HibernateTransactionManager;"
parent="abstractSessionFactoryHost" />
</property>
<property name="target">
<bean class="&EventDaoImpl;"
parent="abstractSessionFactoryHost" />
</property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
Strangely, in Spring only configuration without explicit setting of autocommit policy (I guess it's false by default?) and without proxying the target Spring persists the data...
Here's my Spring only config with pool and without tranxactional proxy
Code:
<beans>
<bean class="&PropertyPlaceholderConfigurer;">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:hibernate.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="&BasicDataSource;"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="&LocalSessionFactoryBean;">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>Attendee.hbm.xml</value>
<value>Event.hbm.xml</value>
<value>Location.hbm.xml</value>
<value>Speaker.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
${hibernate.dialect}
</prop>
<prop key="hibernate.max_fetch_depth">
${hibernate.max_fetch_depth}
</prop>
</props>
</property>
</bean>
<bean id="abstractSessionFactoryHost" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager" class="&HibernateTransactionManager;"
parent="abstractSessionFactoryHost" />
<bean id="eventDao" class="&EventDaoImpl;"
parent="abstractSessionFactoryHost" />
</beans>
Hm...