Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: new records lost after tomcat stops

  1. #11
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Spring before 3.0 isn't usable with multiple transactionmanagers (at least not in a declarative way). Either switch to spring 3 or drop declarative transaction management and do everything by hand (you can wrap the specified calls in a TransactionTemplate). IMO the easiest would be to upgrade to spring 3, but I'm not sure if that is a viable solution (at the moment) for you, that is for you to decide...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  2. #12

    Default

    Thank you very much for your help!

  3. #13

    Default

    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?

  4. #14
    Join Date
    Mar 2013
    Posts
    6

    Default

    springexplorer

    Here is an ORM that works with Microsoft Access
    https://www.kellermansoftware.com/p-...ess-layer.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •