0 Replies Latest reply on Aug 23, 2009 11:19 AM by jadtn

    Can't read with native query a type of CHAR(2)

    jadtn

      Hello
      I'm working with mysql 5 / jboss4.2.2/EJB3/JDK6
      I want from a nativequery read a field of CHAR(n) in a database, when I user varchar , it s works, but if i use char(n), I always get a Character instead of a String.

      CREATE TABLE testchar(
      myid CHAR(2) PRIMARY KEY
      )


      When i user native query to retrive data then I get a java.lang.Character instead of a String.

      q=em.createNativeQuery("SELECT myid FROM testchar");
      q.setMaxResults(2);
      List<Object[]> r= q.getResultList();
      log.info("class="+ r.get(0).getClass()+" "+r.get(0));
       -->return java.lang.Character and value is the first character of the row


      There is someone who have an idea of what is wrong?
      Thanks