title: Android: How to get the last id inserted ORMLite?
body: <p>I am having a problem in executing a query (with ORMLite) that adds a return to 'ultimaConfiguracao' in which to get the last 'id' inserted in the configuration table.</p>
  
  <p>the search method the last configuration is as follows:</p>
  
  <pre><code>public Integer buscaIdUltimaAtualizacao() throws SQLException {
          GenericRawResults&lt;Integer&gt; raw = this.queryRaw("SELECT MAX (id) FROM configuracao", new RawRowMapper&lt;Integer&gt;() {
              Configuracao c = new Configuracao();
              @Override
              public Integer mapRow(String[] columns, String[] results) throws SQLException {
                  if(results[0] != null)
                      return Integer.parseInt(results[0]);
                  else
                      return 0;
              }
          });
          return raw.getFirstResult();
      }
  </code></pre>
  
  <p>Class using sqlite:</p>
  
  <pre><code>@DatabaseTable(tableName = "configuracao", daoClass = ConfiguracaoDao.class)
  
      public class Configuracao {
  
          public Configuracao() {
              /*deixar vazio*/
          }
  
          @DatabaseField(generatedId = true)
          private int id;
  
          @DatabaseField(dataType = DataType.DATE, canBeNull = true)
          private Date ultima_atualizacao_artista;
  
          @DatabaseField(dataType = DataType.DATE, canBeNull = true)
          private Date ultima_atualizacao_diaEvento;
  
          @DatabaseField(dataType = DataType.DATE, canBeNull = true)
          private Date ultima_atualizacao_evento;
      ...
  </code></pre>
  
  <p>Context in which I perform operations:</p>
  
  <pre><code>protected Boolean doInBackground(Void... paths){
          try {
              this.ultimaConfiguracao = this.confDao.queryForId(confDao.buscaIdUltimaAtualizacao().toString());
  
              if(ultimaConfiguracao != null){
                  //baixa somente o que tem atualização
              }
              else{
                  //region MIDIA
                  this.query = new ParseQuery("Midia");
                  this.query.whereEqualTo("ativo", true);
                  query.findInBackground(new FindCallback() {
                      @Override
                      public void done(List list, com.parse.ParseException e) {
                          if(!list.isEmpty()){
                              for(ParseObject pObject : (List&lt;ParseObject&gt;) list) {
                                  publishProgress(((Activity) listener).getString(R.string.m_progress_textView_verificandoAtualizacoes));
                                  Midia md = new Midia();
  ...
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>02-23 22:36:24.097    1446-1453/com.universo91.towersrock W/art﹕ Suspending all threads took: 313.333ms
  02-23 22:36:24.936    1446-1453/com.universo91.towersrock W/art﹕ Suspending all threads took: 651.381ms
  02-23 22:36:25.009    1446-1491/com.universo91.towersrock W/System.err﹕ java.sql.SQLException: Could not perform raw query for SELECT MAX (id) FROM configuracao
  02-23 22:36:25.011    1446-1491/com.universo91.towersrock W/System.err﹕ at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
  02-23 22:36:25.011    1446-1491/com.universo91.towersrock W/System.err﹕ at com.j256.ormlite.dao.BaseDaoImpl.queryRaw(BaseDaoImpl.java:552)
  02-23 22:36:25.011    1446-1491/com.universo91.towersrock W/System.err﹕ at com.universo91.towersrock.DAO.ConfiguracaoDao.buscaIdUltimaAtualizacao(ConfiguracaoDao.java:78)
  02-23 22:36:25.011    1446-1491/com.universo91.towersrock W/System.err﹕ at com.universo91.towersrock.BL.PSTowersRock.doInBackground(PSTowersRock.java:72)
  02-23 22:36:25.011    1446-1491/com.universo91.towersrock W/System.err﹕ at com.universo91.towersrock.BL.PSTowersRock.doInBackground(PSTowersRock.java:39)
  02-23 22:36:25.011    1446-1491/com.universo91.towersrock W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:288)
  02-23 22:36:25.012    1446-1491/com.universo91.towersrock W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  02-23 22:36:25.012    1446-1491/com.universo91.towersrock W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
  02-23 22:36:25.012    1446-1491/com.universo91.towersrock W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  02-23 22:36:25.012    1446-1491/com.universo91.towersrock W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  02-23 22:36:25.012    1446-1491/com.universo91.towersrock W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
  02-23 22:36:25.012    1446-1491/com.universo91.towersrock W/System.err﹕ Caused by: java.sql.SQLException: Getting a writable database from helper DatabaseHelper@28ef97dc failed
  02-23 22:36:25.013    1446-1491/com.universo91.towersrock W/System.err﹕ at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
  02-23 22:36:25.013    1446-1491/com.universo91.towersrock W/System.err﹕ at com.j256.ormlite.android.AndroidConnectionSource.getReadWriteConnection(AndroidConnectionSource.java:68)
  02-23 22:36:25.013    1446-1491/com.universo91.towersrock W/System.err﹕ at com.j256.ormlite.android.AndroidConnectionSource.getReadOnlyConnection(AndroidConnectionSource.java:54)
  02-23 22:36:25.014    1446-1491/com.universo91.towersrock W/System.err﹕ at com.j256.ormlite.stmt.StatementExecutor.queryRaw(StatementExecutor.java:306)
  02-23 22:36:25.014    1446-1491/com.universo91.towersrock W/System.err﹕ at com.j256.ormlite.dao.BaseDaoImpl.queryRaw(BaseDaoImpl.java:550)
  02-23 22:36:25.014    1446-1491/com.universo91.towersrock W/System.err﹕ ... 9 more
  </code></pre>