Hibernate don't have an automatic transaction management system, so you have to issue the begin, commit and roll back commands by yourself.
If you are using spring this can be a lot more easier with spring transaction management API
For example,
@Transactional
void updateFoo(Foo foo){
//do your stuff
}
In the above example a new transaction will be started at the beginning of the updateFoo() method commited at the last line. If there is any problem in between the transaction will be rolled back.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…