title: java.lang.ClassCastException: [B cannot be cast to java.lang.String
body: <p>I have written an entitity class with Field LoginId and Password.</p>
  
  <p>Iam encrypting the passwrd and stoiring it in the db using the AES_ENCRYPT.</p>
  
  <p>I want to retrive only the password which is decrypted. so, im using AES_DECRYPT using NAtiveQueryis in OPen JPA 2.0.</p>
  
  <p>Query i have written is : </p>
  
  <pre><code>Query q = em.createNativeQuery("select AES_DECRYPT(l.password,?2) from loginDetails l where l.loginID = ?1");
  q.setParameter(1, loginId);
  q.setParameter(2, getKey());
  String s = q.getSingleResult();  
  </code></pre>
  
  <p>But im getting the following exception:</p>
  
  <pre><code>java.lang.ClassCastException: [B cannot be cast to java.lang.String
  at com.rcs.chef.validation.UserValidation.decryptedPasswordForID(UserValidation.java:99)
  at com.rcs.chef.validation.UserValidation.validateUser(UserValidation.java:81)
  at com.rcs.chef.validation.UserValidation.activate(UserValidation.java:72)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:226)
  at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:824)
  at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:636)
  at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:724)
  at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)
  at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)
  at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:147)
  at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:640)
  at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:331)
  at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:227)
  </code></pre>
  
  <p>I have even tried  this:</p>
  
  <pre><code>Query q = em.createNativeQuery("select AES_DECRYPT(l.password,?2) from loginDetails l where l.loginID = ?1");
  q.setParameter(1, loginId);
  q.setParameter(2, getKey());
  List&lt;Object&gt; s = q.getResultList();  
  
  String s1 = null;
  for(Object o : s){
      s1= (String) o;
  }
  </code></pre>
  
  <p>Even here also im gettng the same Exception as :</p>
  
  <pre><code>java.lang.ClassCastException: [B cannot be cast to java.lang.Object
  </code></pre>
  
  <p>Can you tell me what is the Mistake with the query adn handling the req.</p>