openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From catalina wei <catalina....@gmail.com>
Subject Re: NullPointer Exception when using Case Expressions
Date Fri, 20 Aug 2010 18:02:12 GMT
Hi Lu,
The trunk level code works fine, could you try OpenJPA SNAPSHOT version
2.1.0 ?

Here is SQL trace from running on DB2 using openjpa-2.1.0.SNAPSHOT:

10890  TRACE  [main] openjpa.Query - Executing query: UPDATE Student2 s SET
s.rank=  CASE WHEN s.totalScore<20 Then 'D'  WHEN s.totalScore>=20 AND
s.totalScore<30 Then 'C'  WHEN s.totalScore>=30 AND s.totalScore<40 Then
'B'  WHEN s.totalScore>=40 AND s.totalScore<50 Then 'A'  Else 'N/A'  END
WHERE s.id = 10
10906  TRACE  [main] openjpa.jdbc.SQL - <t 26780509, conn 12252334>
executing prepstmnt 31090792 UPDATE Student2 t0 SET t0.rank =  CASE  WHEN
t0.totalScore < CAST(? AS DOUBLE) THEN 'D' WHEN t0.totalScore >= CAST(? AS
DOUBLE) AND t0.totalScore < CAST(? AS DOUBLE) THEN 'C' WHEN t0.totalScore >=
CAST(? AS DOUBLE) AND t0.totalScore < CAST(? AS DOUBLE) THEN 'B' WHEN
t0.totalScore >= CAST(? AS DOUBLE) AND t0.totalScore < CAST(? AS DOUBLE)
THEN 'A' ELSE 'N/A' END  WHERE (t0.id = CAST(? AS BIGINT)) [params=?, ?, ?,
?, ?, ?, ?, ?]
10906  TRACE  [main] openjpa.jdbc.SQL - <t 26780509, conn 12252334> [0 ms]
spent

Catlaina
On Fri, Aug 20, 2010 at 1:12 AM, Lu Jiang <jessyever@gmail.com> wrote:

> Hi,all
> I am experiencing the JPA 2.0 new features using openjpa 2.0,but
> currently I was trapped.
> I defined a entity class Student
> @Entity
> public class Student implements Serializable {
>    @Id
>    private Integer id;
> ...
>    private double totalScore;
>    private String rank;
>    //getters and setters
> }
> When I tried to simply update the rank,it all works fine.
>  public void updateRank(Integer id) {
>       String jpql="UPDATE  Student  s "
>                + "SET s.rank= 'F' "
>                + " WHERE s.id = " + id;
>        Query query = em.createQuery(jpql);
>        query.executeUpdate();
>    }
>
> but when I tried to update the rank according to totalScore in the
> following method.
>
>  public void updateRank(Integer id) {
>        String jpql = "UPDATE Student s "
>                + "SET s.rank= "
>                + " CASE WHEN s.totalScore<20 Then 'D' "
>                + " WHEN s.totalScore>=20 AND s.totalScore<30 Then 'C' "
>                + " WHEN s.totalScore>=30 AND s.totalScore<40 Then 'B' "
>                + " WHEN s.totalScore>=40 AND s.totalScore<50 Then 'A' "
>                + " Else 'N/A' "
>                + " END "
>                + " WHERE s.id = " + id;
>        Query query = em.createQuery(jpql);
>        query.executeUpdate();
>    }
>
> Error like below will occur.
> Exception in thread "main" <openjpa-2.0.0-r422266:935683 nonfatal user
> error> org.apache.openjpa.persistence.ArgumentException: null
>        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:827)
>        at org.apache.openjpa.kernel.QueryImpl.updateAll(QueryImpl.java:898)
>        at org.apache.openjpa.kernel.QueryImpl.updateAll(QueryImpl.java:894)
>        at
> org.apache.openjpa.kernel.DelegatingQuery.updateAll(DelegatingQuery.java:582)
>        at
> org.apache.openjpa.persistence.QueryImpl.executeUpdate(QueryImpl.java:348)
>        at
> org.apache.geronimo.sample.jpa20.bean.Facade.updateRank(Facade.java:158)
>        at
> org.apahce.geronimo.sample.jpa20.test.updateRank.main(updateRank.java:20)
> Caused by: java.lang.NullPointerException
>        at
> org.apache.openjpa.jdbc.kernel.exps.AndExpression.appendTo(AndExpression.java:68)
>        at
> org.apache.openjpa.jdbc.kernel.exps.WhenCondition.appendTo(WhenCondition.java:70)
>        at
> org.apache.openjpa.jdbc.kernel.exps.GeneralCaseExpression.appendTo(GeneralCaseExpression.java:114)
>        at
> org.apache.openjpa.jdbc.sql.DBDictionary.appendUpdates(DBDictionary.java:2127)
>        at
> org.apache.openjpa.jdbc.sql.DBDictionary.toBulkOperation(DBDictionary.java:2021)
>        at
> org.apache.openjpa.jdbc.sql.DBDictionary.toUpdate(DBDictionary.java:1933)
>
> Does anyone have idea of this kind of issue?Or I got something wrong
> with the jpql sentence?Hope someone can give me some clue:)Thanks in
> advance!
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message