Hello Marten,
it works now with a little extension.
I have upgraded to Spring3 and use the qualifier with the name of the transactionmanager. But i had to flush the session after each update or insert. Without the flushing the records were deleted again as without a transactionManager (or the false one) when i normally stopped tomcat. After stopping the following lines were logged:
Code:
INFO : org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:769) - closing
INFO : org.hibernate.connection.DriverManagerConnectionProvider.close(DriverManagerConnectionProvider.java:147) - cleaning up connection pool: jdbc:access:///d:/database.mdb?delayedClose=0
INFO : org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:769) - closing
After that the records were deleted. When i terminated (not stopping) tomcat then the records were persistent. Therefore I had to add the flushing after eache insert/update:
Code:
package de.kraemerit.msl.repository;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import de.kraemerit.msl.domain.Article;
import de.kraemerit.msl.domain.Unit;
public class HibernateArticleRepository implements ArticleRepository {
@Autowired
@Qualifier("hibernateSessionFactoryMSAccess")
private SessionFactory sessionFactory;
public HibernateArticleRepository() {
//this.sessionFactory = sessionFactory;
}
@Override
public Article getById(Long id) {
return (Article) getCurrentSession().createQuery("Select a From Article a where a.id = ?").setLong(0, id).uniqueResult();
}
@Override
public Article getByShortDescription(String shortDescription) {
return (Article) getCurrentSession().createQuery("Select a From Article a where a.shortDescription = ?").setString(0, shortDescription).uniqueResult();
}
@Override
public void update(Article article) {
getCurrentSession().saveOrUpdate(article);
getCurrentSession().flush();
}
public void delete(Article article) {
getCurrentSession().delete(article);
getCurrentSession().flush();
}
@Override
public List<Article> getAll(Boolean isValid, Integer start, Integer limit) {
return getCurrentSession().createQuery("Select a From Article a where a.isValid = ? order by a.shortDescription").setBoolean(0, isValid).setFirstResult(start).setMaxResults(limit).list();
}
public Long getCountAll(Boolean isValid) {
return (Long)getCurrentSession().createQuery("Select count(a) From Article a where a.isValid = ?").setBoolean(0, isValid).uniqueResult();
}
@Override
public List<Article> getAllMsl() {
return getCurrentSession().createQuery("Select a From Article a where a.isValid = true order by a.shortDescription").list();
}
protected Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
}
Do you have an idea why the flushing is needed with ms access while with mysql is not?