[jboss-user] [EJB 3.0] - @sqlResultMapping - ClassCastException

lydiachung do-not-reply at jboss.com
Fri Mar 16 14:29:55 EDT 2007

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?


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4028916#4028916

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4028916

More information about the jboss-user mailing list