title: How to retrieve the max id value and store in a int variable?
body: <p>I have some data in my database, and there is an id column which increments automatically whenever a data is stored.</p>
  
  <p>For some purpose I want to retrieve the last row added or the row with max id (which is also the last row). I am writing the below query as:</p>
  
  <pre><code>List&lt;Student&gt; student = sessionFactory.getCurrentSession().createQuery("SELECT * FROM Student ORDER BY id DESC")
  </code></pre>
  
  <p>I don't know whether it is right way to do, but while executing I am getting error like unexpected token: *.</p>
  
  <p>Looking for your valuable suggestion and thanks in advance.  </p>
  
  <pre><code>public void storeData(Student student)
  {
     List&lt;Student&gt; std = sessionFactory.getCurrentSession().createQuery("FROM Student ORDER BY id DESC limit 1").list(); //getting error while executing this statement(unexpected token limit)
  
     System.out.println(std.get(0).getNumber()); //getting error while executing it
  }
  </code></pre>
  
  <p>I am sending the student data through student object in storeData class. I want that after storing data I can access the value of data stored, like I want to store the number value in a variable for further process. But while executing the above I am getting error.</p>