Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere and how handle spring+hibernate exceptions?
    text
    copied!<p>im using spring+hibernate for a desktop application.</p> <p>I'm trying to build it with a layered implementation, so i have:</p> <p><strong>GUI layer --call--> Service layer --call--> DAO layer</strong></p> <p>A small example to better exaplain my situation:</p> <pre><code>// In GUI layer private void actionPerformed(ActionEvent evt){ addUser(); } private void addUser(){ // Check gui validation for user inputs if(inputIsValid()){ String username=nameText.getText(); String pass=passText.getText(); //Now call service layer userService.createUser(username, pass); // Now here i want to show a message to user like // "Operation successful" or "Operation failed" // or more sofisticated message like "User with same name already exists" } } // Service layer @Transactional public void createUser(String name, String pass){ User user=new User(name, pass); userDao.save(user); } // Another service layer example, @Transactional public boolean createUser(String name, String pass){ User user=new User(name, pass); try{ userDao.save(user); } catch(Exception ex){ Log(ex); return false; } return true; // In this case GUI layer can know if save is succesful, but it can't know WHY // the save is failed : some username? DB service shutdown? etc.. } </code></pre> <p>The problem is: who throw exception and who handle it?</p> <p>I think DAO have to throw first exception, and service layer rethrow it, and finally GUI layer handle exception, so i can show message to user, is this good? There is a way to build some ExceptionHandler using spring?</p> <p><strong>What is the best practice to manage exceptions using spring+hibernate?</strong></p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload