GAE 数据存储中的 JPA 错误

发布于 2024-12-10 05:11:12 字数 613 浏览 0 评论 0原文

我试图让我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

垂暮老矣 2024-12-17 05:11:12

错误消息很奇怪,所以这可能不是您唯一的错误,但您的查询是错误的。 select * 是 SQL,而不是 JPQL。正确的查询是

select p from PersistableItem p

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

select p from PersistableItem p
美男兮 2024-12-17 05:11:12

您的项目中(或项目的依赖项中)是否存在“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")

清晰传感 2024-12-17 05:11:12

即使使用正确的 JPQL 查询,我也遇到了同样的错误,并解决了在 persistence.xml 中添加类声明的问题

<persistence-unit name="appengine-transactions-optional">
    <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
    <class>it.gustaff.data.Place</class>
    <class>it.gustaff.data.Menu</class>
    <properties>
        <property name="datanucleus.NontransactionalRead" value="true"/>
        <property name="datanucleus.NontransactionalWrite" value="true"/>
        <property name="datanucleus.ConnectionURL" value="appengine"/>
    </properties>
</persistence-unit>

I had the same error even with the right JPQL query and solved adding the class declarations in the persistence.xml

<persistence-unit name="appengine-transactions-optional">
    <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
    <class>it.gustaff.data.Place</class>
    <class>it.gustaff.data.Menu</class>
    <properties>
        <property name="datanucleus.NontransactionalRead" value="true"/>
        <property name="datanucleus.NontransactionalWrite" value="true"/>
        <property name="datanucleus.ConnectionURL" value="appengine"/>
    </properties>
</persistence-unit>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文