Here is my applicationContext.xml. I am currently not implementing a transaction proxy as the backend is mysql, and it seems unneccesary to use tx's with a MyISAM DB.
Code:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="myDataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/wwbc</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>org/wwbc/dao/mappings/Headlines.hbm</value>
<value>org/wwbc/dao/mappings/News.hbm</value>
<value>org/wwbc/dao/mappings/Users.hbm</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
net.sf.hibernate.dialect.MySQLDialect</prop>
<prop key="show_sql">true</prop>
</props>
</property>
<property name="dataSource">
<ref bean="myDataSource"/>
</property>
</bean>
<bean id="org.wwbc.dao.services.NEWS_SERVICE"
class="org.wwbc.dao.hibernate.NewsDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="org.wwbc.dao.services.USERS_SERVICE"
class="org.wwbc.dao.hibernate.UsersDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
Here is my method implementation in my DAO for deletion of the object.
Code:
public class NewsDAOImpl extends HibernateDaoSupport implements INewsDAO {
public void deleteNews(final News news) throws DAOException {
HibernateCallback callback = new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
session.delete(news);
session.flush();
return null;
}
};
try {
callback.doInHibernate(getSession());
} catch (Exception e) {
throw new DAOException("Could not delete news article. (News ID: " + news.getId() + ")", e);
}
}
}
I really didn't think i'd have to use the flush() method on my own - my understanding was that HibernateDaoSupport handled this for me (as I said in my original post). using flush() works though, but it would be nice to know if this is truly neccesary or if something else is horribly wrong.
Thanks,
Ryan