Hibernate not executing queries until response is commited
<p>I am doing few hibernate save operations in spring's transactional service class.
My expectation is that by the time method execution finishes hibernate should write data to database.
But hibernate is actually executing those queries only when controller is about to return a response.</p>

<p>My sample code is as follows. </p>

<pre><code>@Controller
public class TestController {
    @Autowired
    private SaveService saveService;

    @RequestMapping(value = "saveData", method = RequestMethod.POST)
    public String saveData(HttpServletRequest request, Model model) {
        try {       
        saveService.saveData(object1, object2, object3); // LINE 1
        sendEmail();                                     // LINE 2
        //some code here                 // LINE 3  
        } catch(Exception e) {
            //log exception
            //return error message      
        }
    }
}


@Service("saveService")
@Transactional
public class SaveServiceImpl implements SaveService {
    @Autowired
    private SaveDAO saveDAO;

    public void saveData(Object objec1, Object objec2, Object objec3) {
        saveDAO.save(object1);
        saveDAO.save(object2);
        saveDAO.save(object3);  
    }   
}
</code></pre>

<p>In above code I am calling SaveService.saveData() method from controller. And if save is successful I want to go ahead and send an email. But if for some reason SaveService.saveData() throws an exception i don't want
to send the email.<br/>
When I performed some tests it was observed that even if SaveService.saveData() throws an exception it's not thrown 
until the email is sent from controller. <br/> I want that if a call to saveService.saveData() at 'LINE 1' in controller 
throws an exception the next line that sends email should not get executed. <br/>
I wanted to know if this is expected hibernate behavior and if it is what can I do to tell hibernate to execute
queries before exiting service methods.<br/>
Thank you.</p>