Wie man letzten Datensatz aus der Mysql-Einsatz von Hibernate?

List<Lahetys> last = session.createQuery("from lahetys order by lahetysNro DESC LIMIT 1").list();

und in der log hab ich:

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

Was passiert ist "von LAHETYS"? Was ist die beste Praxis zu behandeln, die mit HQL-oder/und mit SQL?

Anderes problem:

Lahetys last = (Lahetys)session.createSQLQuery("select * from lahetys order by lahetysNro DESC LIMIT 1").uniqueResult();
session.getTransaction().commit();  

und ich bekomme eine exception:

Ljava.lang.Object; cannot be cast to Lahetys 

So, ich kann nicht werfen ein Objekt, um meine Lahetys-Objekt, komisch?

Danke!
Sami

InformationsquelleAutor Sami | 2012-10-25

Schreibe einen Kommentar