title: How to capture the mybatis exception "org.apache.ibatis.exceptions.PersistenceException"?
body: <p>Here is the code sample, I want to capture the exception throwed by mybatis:</p>
  
  <pre><code>String resource = "com/sureone/server/db/mybatis-config.xml";
  Reader reader = null;
  try {
      reader = Resources.getResourceAsReader(resource);
  } catch (IOException e) {
      e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
  }
  SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
  sqlSession = factory.openSession(true);
  tUserMapper = sqlSession.getMapper(TUserMapper.class);
  
  if(tUserMapper.insert(user)&gt;0){     &lt;===Exception throwed here for duplicate entry problem 
     return verifyLogin(user.getAccount(),user.getPassword());
  }
  return null;
  </code></pre>
  
  <p>The exception I want to captured:</p>
  
  <pre><code>org.apache.ibatis.exceptions.PersistenceException: 
  ### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'userName' for key 'account_UNIQUE'
  </code></pre>