Transactions, Spring.
@Transactional(propagation = Propagation.REQUIRED) public Long registerEntity(Entity entity) { // execute some SQL statements like // inserting an entity into the db // and return the autogenerated id return id; } } In the other scenario, consider that this registerEntity() method is being called