我正在尝试获取插入数据库的最后一个实体,我认为这将是一件非常简单的事情,但是我尝试的每个查询都会导致某种异常被抛出
我使用的代码是:
@Override
public DataStoreMark getLastMark() {
String selectQuery = "from Mark";
Query query = em.createNativeQuery(selectQuery, DataStoreMark.class);
try {
return (DataStoreMark) query.getSingleResult();
} catch (NoResultException e) {
log.error("Couldn't find any Marks in the DataStore.");
}
return null;
}
但是,此代码会引发 PesistenceException:
org.hibernate.exception.SQLGrammarException: 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 milestone' at line 1
而且数据库里肯定有记录。
有任何想法吗?