Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2286

SELECT COUNT with date litteral,used more than once, provokes ArgumentException: Attempt to compare incompatible types class java.util.Date and class org.apache.openjpa.jdbc.sql.Raw

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.0
    • 2.1.2, 2.2.1.1, 2.2.3, 2.4.0
    • query
    • None
    • tested with
      openjpa-all-2.2.0.jar
      openjpa-all-2.3.0-20121019.065014-74.jar

      org.apache.derby.jdbc.ClientDriver
      com.ibm.as400.access.AS400JDBCDriver




    Description

      a select count with date literal throws exception if used more than once in EntityManagerFactory

      SELECT COUNT FROM TestCountWithDate x WHERE LOWER(x.name) LIKE '%vier%' AND x.adate =

      {d '2007-12-12'}

      INFO: qry_0=SELECT COUNT FROM TestCountWithDate x WHERE LOWER(x.name) LIKE '%vier%' AND x.adate = {d '2007-12-12'}

      Exception in thread "main" <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to compare incompatible types "class java.util.Date" and "class org.apache.openjpa.jdbc.sql.Raw".
      at org.apache.openjpa.jdbc.kernel.exps.CompareEqualExpression.appendTo(CompareEqualExpression.java:101)
      at org.apache.openjpa.jdbc.kernel.exps.AndExpression.appendTo(AndExpression.java:65)
      at org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.buildWhere(SelectConstructor.java:312)
      at org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.evaluate(SelectConstructor.java:94)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.createWhereSelects(JDBCStoreQuery.java:360)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeQuery(JDBCStoreQuery.java:193)
      at org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeQuery(ExpressionStoreQuery.java:783)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
      at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
      at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:330)
      at client.Client.doQueries(Client.java:51)
      at client.Client.main(Client.java:101)

      testprogram

      //export CLASSPATH=$JAVA_HOME/db/lib/derbyclient.jar:/opt/apache-openjpa-2.2.0/openjpa-all-2.2.0.jar:../:~/tmp/build/website1/build/WEB-INF/classes/
      //javac Client.java
      //java client.Client hoefsmidb
      /*
      create table testCountWithDate(id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY primary key,Name char(32) not null,aDATE DATE NOT NULL);
      INSERT INTO testCountWithDate(name,aDate) values ('hvieren','2007-12-12');
      INSERT INTO testCountWithDate(name,aDate) values ('vierendeels','2012-10-26');
      INSERT INTO testCountWithDate(name,aDate) values ('tshvr','2012-10-27');
      */
      package client;

      import javax.persistence.EntityManager;
      import javax.persistence.Persistence;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Query;

      import java.util.Collection;
      import java.util.List;

      import java.util.logging.*;

      import entities.APP.TestCountWithDate;

      public class Client
      {
      private static final Logger logger=Logger.getLogger(Client.class.getName());

      private static EntityManagerFactory emf;
      private static EntityManager em;

      private static String qry_0="SELECT COUNT FROM TestCountWithDate x WHERE LOWER(x.name) LIKE '%vier%' AND x.adate =

      {d '2007-12-12'}";
      private static String qry_1="SELECT x FROM TestCountWithDate AS x WHERE LOWER(x.name) LIKE '%vier%' AND x.adate = {d '2007-12-12'}

      order by x.id";

      private static void createTransactionalEntityManager()

      { em=emf.createEntityManager(); em.getTransaction().begin(); logger.info("createTransactionalEntityManager done"); }

      private static void closeTransactionalEntityManager()

      { em.getTransaction().commit(); em.close(); logger.info("closeTransactionalEntityManager done"); }

      public static String doQueries()
      {
      long qry_count=-1;
      logger.info("qry_0="+qry_0);
      qry_count=em.createQuery(qry_0,Long.class).getSingleResult();
      logger.info("qry_count="+qry_count);

      /***
      Exception in thread "main" <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to compare incompatible types "class java.sql.Date" and "class org.apache.openjpa.jdbc.sql.Raw".
      at org.apache.openjpa.jdbc.kernel.exps.CompareEqualExpression.appendTo(CompareEqualExpression.java:101)
      at org.apache.openjpa.jdbc.kernel.exps.AndExpression.appendTo(AndExpression.java:65)
      at org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.buildWhere(SelectConstructor.java:312)
      at org.apache.openjpa.jdbc.kernel.exps.SelectConstructor.evaluate(SelectConstructor.java:94)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.createWhereSelects(JDBCStoreQuery.java:360)
      at org.apache.openjpa.jdbc.kernel.JDBCStoreQuery.executeQuery(JDBCStoreQuery.java:193)
      at org.apache.openjpa.kernel.ExpressionStoreQuery$DataStoreExecutor.executeQuery(ExpressionStoreQuery.java:783)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
      at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
      at org.apache.openjpa.persistence.QueryImpl.getSingleResult(QueryImpl.java:330)
      ***/
      /********
      logger.info("qry="+qry_1);
      Query qry=em.createQuery(qry_1);

      List qry_rslts=qry.getResultList();
      //if(qry_rslts==null || qry_rslts() !=0)
      int qry_rslts_size=qry_rslts.size();
      logger.info("qry_rslts_size="+qry_rslts_size);
      for(Object o:qry_rslts)

      { logger.info("o="+o); }

      //for
      *******/
      return("OK");
      }//doQueries

      public static void main(String[] args)

      { String pu_name=args[0]; emf=Persistence.createEntityManagerFactory(pu_name); createTransactionalEntityManager(); doQueries(); closeTransactionalEntityManager(); emf.close(); emf=Persistence.createEntityManagerFactory(pu_name); createTransactionalEntityManager(); doQueries(); closeTransactionalEntityManager(); createTransactionalEntityManager(); doQueries(); closeTransactionalEntityManager(); System.exit(0); }

      //main
      }
      ---------------------
      package entities.APP;

      import java.util.*;
      import javax.persistence.*;

      /**

      • Auto-generated by:
      • org.apache.openjpa.jdbc.meta.ReverseMappingTool$AnnotatedCodeGenerator
        */
        @Entity
        @Table(schema="APP", name="testCountWithDate")
        public class TestCountWithDate {
        @Basic
        @Column(nullable=false)
        @Temporal(TemporalType.DATE)
        private Date adate;

      @Id
      private int id;

      @Basic
      @Column(nullable=false, length=32)
      private String name;

      public TestCountWithDate() {
      }

      public TestCountWithDate(int id)

      { this.id = id; }

      public Date getAdate() { return adate; }

      public void setAdate(Date adate) { this.adate = adate; }

      public int getId() { return id; }

      public void setId(int id) { this.id = id; }

      public String getName()

      { return name; }

      public void setName(String name)

      { this.name = name; }

      }

      Attachments

        Activity

          People

            jpaheath Heath Thomann
            hvieren Herman Vierendeels
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: