Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa datanucleus+;postgresql+;简单更新子句中的jpql错误_Jpa_Datanucleus - Fatal编程技术网

Jpa datanucleus+;postgresql+;简单更新子句中的jpql错误

Jpa datanucleus+;postgresql+;简单更新子句中的jpql错误,jpa,datanucleus,Jpa,Datanucleus,我已经试着解决这个问题6个小时了,但我一辈子都想不出来 我正在使用: datanucleus 3.2.1,带JPA x86_64-unknown-linux-gnu上的PostgreSQL 8.4.4,由GCC(GCC)3.4.6 20060404(Red Hat 3.4.6-10)编译,64位 postgres jdbc驱动程序版本:9.1-901.jdbc4 我试图通过jpql执行一个非常简单的更新查询。查询基本上是: UPDATE MyClass x SET x.recordStatu

我已经试着解决这个问题6个小时了,但我一辈子都想不出来

我正在使用:

  • datanucleus 3.2.1,带JPA
  • x86_64-unknown-linux-gnu上的PostgreSQL 8.4.4,由GCC(GCC)3.4.6 20060404(Red Hat 3.4.6-10)编译,64位
  • postgres jdbc驱动程序版本:9.1-901.jdbc4
我试图通过jpql执行一个非常简单的更新查询。查询基本上是:

UPDATE MyClass x SET x.recordStatus='0' where x.token='1234'
我的代码如下所示:

    String updateClause = "UPDATE MyClass x SET x.recordStatus='0' where x.token='1234'";
    EntityManager entityManager = getDefaultEntityManager();
    Query query = entityManager.createQuery(updateClause);
    query.executeUpdate();
    entityManager.close();
我遇到的问题是驱动程序抛出了一个错误

Caused by: org.postgresql.util.PSQLException: ERROR: column "a0" of relation "my_class" does not exist
                                Position: 42
                                    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2102)
                                    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1835)
这有点不正常,因为postgres接受以下形式的更新:

update some_table x set field=value where field2=another_value
……但不是

update some_table x set x.field=value where x.field2=another_value
(即执行更新时,SET或WHERE子句中没有别名)

我已尝试编写我的jpql查询:

  • 在SET和WHERE子句中不使用别名(update MyClass x SET recordStatus='0'WHERE token='1234'),但日志显示datanucleus会将查询编译为使用别名的本机查询

  • 根本不使用别名(甚至不使用类名),但在本例中,datanucleus会抛出一个错误,即我必须使用别名

有关依赖项的完整列表,请参阅本文末尾

我的问题是:

  • 我怎样才能克服这个问题?我做错了什么
  • 一个重要特性的非常基本的用例在Datanucleus中失败。这不是第一次发生这样的事情。例如,请参阅以下帖子: 我还有其他例子。 这看起来不太好,我也不明白为什么,因为我真的找不到其他帖子抱怨这类问题。这种组合(datanucleus+postgres)真的没有使用吗?它看起来几乎被遗弃了
谢谢你抽出时间。 亲切问候,, 安德烈

我的依赖项列表:

    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jpa_2.0_spec</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901.jdbc4</version>
    </dependency>

    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <version>3.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-rdbms</artifactId>
        <version>3.2.0-release</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-api-jpa</artifactId>
        <version>3.2.0-release</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-connectionpool</artifactId>
        <version>2.0.3</version>
    </dependency>
    <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo2-api</artifactId>
        <version>2.2</version>
    </dependency>

org.apache.geronimo.specs
geronimo-jpa_2.0_规范
1
postgresql
postgresql
9.1-901.jdbc4
org.datanucleus
数据核核心
3.2.1
org.datanucleus
datanucleus关系数据库
3.2.0-发布
org.datanucleus
datanucleus api jpa
3.2.0-发布
org.datanucleus
datanucleus连接池
2.0.3
javax.jdo
jdo2api
2.2

如果您对某些软件有问题,我个人会提出一个关于该软件的问题,并向编写该软件的人员演示如何演示(因为他们可能没有看到,或者没有遇到您的用例)。这可能比在其他网站上称事情“无用”更有效率。在过去的3年中,我在DataNucleus上使用过多次PostgreSQL,从未出现过问题,但没有进行批量更新;也许他们使用的语法有一些问题,这对很多人有效,但对Postgresql无效?不要认为JDO是2.2 btw。。。我用的是3.0.1。不可否认,说它没用不是最好的选择。然而,这正是问题所在。我没有一个非常特殊的用例。我只希望通过jpql用例进行最基本的更新。为了不冒犯任何人,重新编写了文本:)谢谢。您可以尝试以下请求:更新MyClass SET recordStatus='0',其中token='1234'是我做的。它抱怨我没有别名(datanucleus例外)