title: How to get last record from Mysql using Hibernate?
body: <pre><code>List&lt;Lahetys&gt; last = session.createQuery("from lahetys order by lahetysNro DESC LIMIT 1").list();
  </code></pre>
  
  <p>and in the log I got:</p>
  
  <pre><code>INFO: Hibernate: select  from order by  lahetysNro DESC LIMIT 1
  WARN: SQL Error: 1064, SQLState: 42000
  ERROR: You have an error in your SQL syntax; check the manual that corresponds to your       MySQL server version for the right syntax to use near 'from order by  lahetysNro DESC LIMIT 1' at line 1
  </code></pre>
  
  <p>What has happend to "from LAHETYS"? What is the best practice to handle that with HQL or/and with SQL?</p>
  
  <p>Another problem:</p>
  
  <pre><code>Lahetys last = (Lahetys)session.createSQLQuery("select * from lahetys order by lahetysNro DESC LIMIT 1").uniqueResult();
  session.getTransaction().commit();  
  </code></pre>
  
  <p>and I get a exception:</p>
  
  <pre><code>Ljava.lang.Object; cannot be cast to Lahetys 
  </code></pre>
  
  <p>So I can't cast an object to my Lahetys-object, weird?</p>
  
  <p>Thank you!
  Sami</p>