Search code examples
javaspringhibernateormtransactions

Open Session In View (OSIV) and Hibernate Session flush


Following is a hypothetical situation on Spring 3.x and Hibernate3.x

I have a service layer in spring which invokes 3 DAOs to construct a model. The DAOs are transactional(@Transactional) and have lazy loaded hibernate collections.
The service method causes a few updates ,along with the fetch of data.

A typical DAO method will be as follows -

public O create(I entity) throws GenericException {
    getOrCreateSession().save(entity);
    return (O)entity;
}

I have the following questions around OSIV -
1.How many times is this session flushed(database update) in the default AUTO mode?
2.Can OSIV be made to extend the session beyond a single request (to a conversation)?


Solution

    1. The AUTO flush mode will execute the pending DML statements when:
    • the current transaction is committed
    • when a query might target an entity table, that's current enqueued for flushing
    1. Spring Webflow has support for long conversations.