Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-28

native query returns strange object instead of String

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.0
    • 1.1.2
    • None
    • None
    • Ubuntu 12.04, JBoss Application Server EAP 5.1.2, MySQL-Galera 5.5.29, OpenJDK 1.6.0_27

    Description

      MariaDB Java connector fails where MySQL connector, Postgres, Oracle etc works fine.


      I have a JPA bean with a simple method:

      public static CertificateInfo findFirstCertificateInfo(EntityManager entityManager, String issuerDN, String serialNumber) {
      CertificateInfo ret = null;
      final Query query = entityManager
      .createNativeQuery(
      "SELECT a.fingerprint, a.subjectDN, a.cAFingerprint, a.status, a.type, a.serialNumber, a.expireDate, a.revocationDate, a.revocationReason, "
      + "a.username, a.tag, a.certificateProfileId, a.updateTime FROM CertificateData a WHERE a.issuerDN=:issuerDN AND a.serialNumber=:serialNumber",
      "CertificateInfoSubset2");
      query.setParameter("issuerDN", issuerDN);
      query.setParameter("serialNumber", serialNumber);
      query.setMaxResults(1);
      @SuppressWarnings("unchecked")
      final List<Object[]> resultList = (List<Object[]>) query.getResultList();
      if (!resultList.isEmpty()) {
      Object[] fields = resultList.get(0);
      // The order of the results are defined by the SqlResultSetMapping annotation
      System.out.println("object: "+fields[0]);
      System.out.println("type: "+fields[0].getClass().getName());

      String fingerprint = (String) fields[0];
      String subjectDN = (String) fields[1];
      String cafp = (String) fields[2];
      int status = ValueExtractor.extractIntValue(fields[3]);
      int type = ValueExtractor.extractIntValue(fields[4]);
      long expireDate = ValueExtractor.extractLongValue(fields[5]);
      long revocationDate = ValueExtractor.extractLongValue(fields[6]);
      int revocationReason = ValueExtractor.extractIntValue(fields[7]);
      String username = (String) fields[8];
      String tag = (String) fields[9];
      int cProfId = ValueExtractor.extractIntValue(fields[10]);
      long updateTime;
      if (fields[11] == null)

      { updateTime = 0; // Might be null in an upgraded installation }

      else

      { updateTime = ValueExtractor.extractLongValue(fields[11]); }

      ret = new CertificateInfo(fingerprint, cafp, serialNumber, issuerDN, subjectDN, status, type, expireDate, revocationDate,
      revocationReason, username, tag, cProfId, updateTime);
      }
      return ret;
      }


      @SqlResultSetMapping(name = "CertificateInfoSubset2", columns =

      { @ColumnResult(name = "fingerprint"), @ColumnResult(name = "subjectDN"), @ColumnResult(name = "cAFingerprint"), @ColumnResult(name = "status"), @ColumnResult(name = "type"), @ColumnResult(name = "expireDate"), @ColumnResult(name = "revocationDate"), @ColumnResult(name = "revocationReason"), @ColumnResult(name = "username"), @ColumnResult(name = "tag"), @ColumnResult(name = "certificateProfileId"), @ColumnResult(name = "updateTime") }

      ),


      The table looks like:

      CREATE TABLE CertificateData (
      fingerprint VARCHAR(250) BINARY NOT NULL,
      base64Cert LONGTEXT,
      cAFingerprint VARCHAR(250) BINARY,
      certificateProfileId INT(11) NOT NULL,
      expireDate BIGINT(20) NOT NULL,
      issuerDN VARCHAR(250) BINARY NOT NULL,
      revocationDate BIGINT(20) NOT NULL,
      revocationReason INT(11) NOT NULL,
      rowProtection LONGTEXT,
      rowVersion INT(11) NOT NULL,
      serialNumber VARCHAR(250) BINARY NOT NULL,
      status INT(11) NOT NULL,
      subjectDN VARCHAR(250) BINARY NOT NULL,
      subjectKeyId VARCHAR(250) BINARY,
      tag VARCHAR(250) BINARY,
      type INT(11) NOT NULL,
      updateTime BIGINT(20) NOT NULL,
      username VARCHAR(250) BINARY,
      PRIMARY KEY (fingerprint)
      );


      Running the query I get:

      java.lang.ClassCastException: [B cannot be cast to java.lang.String
      at org.cesecore.certificates.certificate.CertificateData.findFirstCertificateInfo(CertificateData.java:760)
      at org.cesecore.certificates.certificate.CertificateStoreSessionBean.findFirstCertificateInfo(CertificateStoreSessionBean.java:387)


      CertificateData.java:760 is the line from above:
      String fingerprint = (String) fields[0];

      The System.out.println debug output prints strange things:
      [STDOUT] (http-0.0.0.0-8443-1) object: [B@25073d81
      [STDOUT] (http-0.0.0.0-8443-1) type: [B

      Attachments

        Activity

          People

            wlad Vladislav Vaintroub
            primetomas Tomas Gustavsson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.