Announcement Announcement Module
Collapse
No announcement yet.
HibernateInterceptor not working with 'readOnly' transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateInterceptor not working with 'readOnly' transaction

    This post was submitted to 'Data Access' but no response yet. It seems more suitable in this area.

    We're working on a Spring/Hibernate project and found problems with HibernateInterceptor.

    We use declarative transaction demarcation and set all finder methods to be PROPOGATION_REQUIRED and 'readOnly'. To test the 'readOnly' status a typical finder in DAO has signature as follows:

    public class ProductDao extends HibernateDaoSupport implements IProductDao {
    public Product findProductById(Integer pid) {
    Product p = new Product();
    // set properties for p
    getHibernateTemplate().saveOrUpdate(p);
    }
    }

    The above code works fine -- JUnit issue an exception (write operation voilates 'readOnly' attribute) and no data is persisted to database.

    However, when we switch to HibernateInterceptor (we need to handle app exceptions within callback code), the method is like:

    public Product findProductById(Integer pid) {
    Session session =
    SessionFactoryUtils.getSession(getSessionFactory() ,false);
    try {
    Product p = new Product();
    // set properties for p
    session.saveOrUpdate(p);
    } catch (HibernateException ex) {
    throw SessionFactoryUtils.convertHibernateAccessExceptio n(ex);
    }
    }

    The product instance was saved into database and no any exception!

    We're using Commons DBCP with SQL Server 2000.
    Hibernate 3.0.5 and Spring 1.2.1.

    Any suggestion is highly appreciated.

    ginchang
Working...
X