0 Replies Latest reply on Mar 16, 2007 2:29 PM by Lydia Chung

    @sqlResultMapping - ClassCastException

    Lydia Chung Newbie

      I set up a SqlResultMapping for the User entity.

      @SqlResultSetMapping(name="User", entities={
       @EntityResult(entityClass=User.class, fields = {
       @FieldResult(name="userid", column="userid"),
       @FieldResult(name="username", column="username")
       })}
      )
      @NamedNativeQuery(name="GetUsers",
       query="select userid, username from user",
       resultSetMapping="User")


      Then I want to query the a list of users.

      List userList = em.createNamedQuery("GetUsers").getResultList();


      It returns me a list of objects and when I tried to cast the object to User, it throws ClassCastException.

      User user = (User) userList.get(0)


      Is there a way that I can get User class type back?

      Thanks,