I am using spring-4 with hibernate-5 with annotation based configuration. in my application I have one dao function which will save/update by saveorupdate() of session object . from service layer I am calling dao function twice : 1) for inserting a new object and 2) updating same object with some property change one more time. and my service function is in @Transactional.
problem : I am able to insert first time but after that its not updating same object. but its updating if I am using @Transactional at dao method(but its not correct approach).
I have given a sample example(same as my actual code) as below.
@Service
public class TransactionService{
public boolean calculate(){
Object obj = new Object
insertOrUpdate(obj);
obj.setNewProperty();
insertOrUpdate(obj);
}
@Transactional
public void insertOrUpdate(Object obj){
dao.saveOrUpdate(obj);
}
}
can you guys help me out for this issue. Thanks,