I use spring 1.2.6 with hsqldb 1.7.3 and hibernate 3.
i have a simple DAO that extends HibernateDaoSupport and uses HibernateTemplate. When i perfom a simple insert of a row in the database, the operation is not commited.
if i do it trough a main that uses simple hibernate tx.begin and tx.commit everything goes right.
Here is my DAO code:
i have the following spring configuration file:Code:public class UniteDao extends HibernateDaoSupport implements UniteDAOIF { protected static ResourceBundle bundle = ResourceBundle.getBundle("coach.dao.impl.hibernate.message"); public Long create(Object unite) throws CoachDaoException { if (!(unite instanceof UniteIF)) throw new CoachDaoException(bundle.getString("dao.badtype")); try { Long res; res = (Long)getHibernateTemplate().save(unite); return res; } catch (Exception e) { throw new CoachDaoException(bundle.getString("dao.hibernate.error"), e); } } } }
i have a configuration file for hibernate in a propertie fileCode:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="gestionnaireTache" class="coach.service.impl.basic.GestionnaireTache"> </bean> <bean id="gestionnaireRessource" class="coach.service.impl.basic.GestionnaireRessource"> </bean> <bean id="coachFactory" class="coach.model.impl.basic.ModelBasicFactory"> <property name="gestionnaireRessource"> <ref bean="gestionnaireRessource" /> </property> <property name="gestionnaireTache"> <ref bean="gestionnaireTache" /> </property> </bean> <!-- Session factory pour Hibernate --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="mappingResources"> <list> <value>coach/model/impl/basic/Unite.hbm.xml</value> <value> coach/model/impl/basic/Description.hbm.xml </value> </list> </property> </bean> <!-- Gestionnaire de transaction pour Hibernate --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- Interceptor AOP pour hibernate --> <bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- DAO pour la gestion des Unites --> <bean id="uniteDaoTarget" class="coach.dao.impl.hibernate.UniteDao"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!-- Proxy genere par Spring pour la gestion des transactions --> <bean id="uniteDaoProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyInterfaces"> <value>coach.dao.UniteDAOIF</value> </property> <property name="interceptorNames"> <list> <value>hibernateInterceptor</value> <value>uniteDaoTarget</value> </list> </property> </bean> </beans>
Code:hibernate.show_sql=true hibernate.max_fetch_depth=1 hibernate.hbm2ddl.auto=update hibernate.connection.driver_class=org.hsqldb.jdbcDriver hibernate.connection.url=jdbc:hsqldb:hsql://localhost/coach hibernate.connection.username=sa hibernate.connection.password= hibernate.dialect=org.hibernate.dialect.HSQLDialect
i have a unit test that checks the creation of an object unite in the database:
I'm sure i'm missing something trivial, but i don't know what. Should i perform tx commit in my DAO ?Code:public class UniteDaoTest extends TestCase { HibernateTemplate hibernateTemplate; ModelBasicFactory mvf; XmlBeanFactory xbf; UniteDAOIF uniteDao; protected void setUp() throws Exception { super.setUp(); ClassPathResource res = new ClassPathResource("coach/applicationContext.xml"); xbf = new XmlBeanFactory(res); mvf = (ModelBasicFactory)xbf.getBean("coachFactory"); uniteDao = (UniteDAOIF)xbf.getBean("uniteDaoTarget"); } protected void tearDown() throws Exception { super.tearDown(); xbf.destroySingletons(); } public void testUniteCreate() throws Throwable { //UniteDao uniteDao = new UniteDao(); //uniteDao.setHibernateTemplate(hibernateTemplate); UniteIF unJourHomme = mvf.getJourHomme(); uniteDao.create(unJourHomme); } }


Reply With Quote