Why is it possible to save entity but not delete if transactional annotation is set to readonly=true

Posted by jakob on Stack Overflow See other posts from Stack Overflow or by jakob
Published on 2010-05-20T12:20:00Z Indexed on 2010/05/27 19:41 UTC
Read the original article Hit count: 155

Filed under:
|
|

Hello experts!

My class is annotated with org.springframework.transaction.annotation.Transactional like this:

@Transactional(readOnly = true)
public class MyClass {

I then have a dao class:

@Override
public void delete(final E entity) {
    getSession().delete(entity);
}

@Override
public void save(final E entity) {
    getSession().saveOrUpdate(entity);
}

Then I have two methods in MyClass

@Transactional(readOnly = false)
public void doDelete(Entity entity){
    daoImpl.delete(entity)
}

//@Transactional(readOnly = false)
public void doSave(){
    daoImpl.save(entity)
}

Saving and deleting works like a charm. But if I remove the @Transactional(readOnly = false) on doDelete method deletion stops working, Saving works with and without the method annotation. So my question is: WHY?

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about spring