0
我试图获取插入到数据库中的最后一个实体,我认为这是一个非常简单的事情,但是我尝试的每个查询都会导致某种异常抛出选择最后一个插入了休眠的实体
使用的代码IM是:
@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
,绝对没有在数据库中的记录。
任何想法?
你在混合使用HQL查询的'createNativeQuery',甚至纠正它不会给你最后插入的实体。 – madth3