GAE 数据存储中的 JPA 错误
我试图让我的 GAE 应用程序从数据存储区中提取一些记录,但不断收到此信息:
javax.persistence.PersistenceException: Class PersistableItem for query has not been resolved. Check the query and any imports specification
它来自此处的方法:
public List<PersistableItem> listItems() {
EntityManager em = EMFService.get().createEntityManager();
// Read the existing entries
Query q = em.createQuery("select * from PersistableItem");
List<PersistableItem> items = q.getResultList();
return items;
}
从我读到的内容来看,这是关于导入我的 PersistableItem 类,但我很困惑,因为我已经在.java 代码文件。
I'm trying to have my GAE app pull some records from the Datastore but keep getting this:
javax.persistence.PersistenceException: Class PersistableItem for query has not been resolved. Check the query and any imports specification
It's from the method here:
public List<PersistableItem> listItems() {
EntityManager em = EMFService.get().createEntityManager();
// Read the existing entries
Query q = em.createQuery("select * from PersistableItem");
List<PersistableItem> items = q.getResultList();
return items;
}
From what I've read this is about importing my PersistableItem class but I'm confused as I already do that in the .java code files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误消息很奇怪,所以这可能不是您唯一的错误,但您的查询是错误的。 select * 是 SQL,而不是 JPQL。正确的查询是
The error message is strange, so this might not be your only error, but your query is wrong. select * is SQL, not JPQL. The correct query is
您的项目中(或项目的依赖项中)是否存在“PersistableItem”类。它是否具有
@Entity
类级别注释。它是否实现了可序列化。在 JPQL 中尝试使用类的完全限定名称(“select * from package1.package2.PersistableItem”)Is the class "PersistableItem" present in your project (or in a dependency of your project). Does it have the
@Entity
class level annotation. Does it implement Serializable. In your JPQL try using the fully qualified name of the class ("select * from package1.package2.PersistableItem")即使使用正确的 JPQL 查询,我也遇到了同样的错误,并解决了在 persistence.xml 中添加类声明的问题
I had the same error even with the right JPQL query and solved adding the class declarations in the persistence.xml