私はこれを6時間修正しようとしましたが、一生理解できませんでした.
私は使用しています:
- JPAを使用したdatanucleus 3.2.1
- GCC gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-10) でコンパイルされた x86_64-unknown-linux-gnu 上の PostgreSQL 8.4.4、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 + jpa + oracle. テーブルが存在しないという奇妙なエラー 他の例もあります。これはあまり良くないように見えますが、その理由がわかりません。なぜなら、この種の問題について不平を言っている他の投稿を実際に見つけることができなかったからです。この組み合わせ (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>