Hmm, having show_sql set to true displays subtle differences. But the overall amount of SQL queries is nearly the same.
The point is: without Spring the SQL log shows up very fast, with Spring I can nearly watch each query one after another.
Regarding the DataSource:
(note: this is currently a non-web standalone test)
In hibernate.cfg.xml:
Code:
<session-factory>
<property name="hibernate.dialect"
>net.sf.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class"
>com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url"
>jdbc:mysql://141.***:3306/myDB?relaxAutoCommit=true</property>
<property name="hibernate.connection.username">xxx</property>
<property name="hibernate.connection.password">xxx</property>
...
In applicationContext.xml:
Code:
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://141.***:3306/myDB?relaxAutoCommit=true</value>
</property>
<property name="username">
<value>xxx</value>
</property>
<property name="password">
<value>xxx</value>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="myDataSource"/>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.connection.pool_size">1</prop>
<!-- etc other properties -->
...
<bean id="objectDAO" class="MyDAOImpl">
<property name="sessionFactory">
<ref bean="mySessionFactory" />
</property>
</bean>
...
Well, the Java code isn't any spectacular (both in main(String[] a))
formerly:
Code:
Session s = MyHibernateHelper.currentSession();
Transaction tx = s.beginTransaction();
try {
s.saveOrUpdate(o);
tx.commit();
}
catch (HibernateException e) {
tx.rollback();
}
MyHibernateHelper.closeSession();
Now:
Code:
SessionFactory sessionFactory =
(SessionFactory)MyDAOHelper.getBean("mySessionFactory");
Session s = SessionFactoryUtils.getSession(sessionFactory, true);
myDAO = (MyDAO)MyDAOHelper.getBean("objectDAO");
myDAO.save(o);
s.flush();
SessionFactoryUtils.closeSessionIfNecessary(s, sessionFactory);
and in MyDAOImpl.save(o):
getHibernateTemplate().saveOrUpdate(o);
I think this is all standard code.
(Sorry for the length of this reply)
I'm going to check P6Spy in any case, thanks.
Oliver