There is a java.lang.ClassCastException: ejb.persistence.User.

My servlet code is:
        private void showUser(HttpServletRequest request,
  |                     HttpServletResponse response) {
  |             try {
  |                     InitialContext ctx = new InitialContext();
  |                     userSession = (userSession) 
ctx.lookup("userSessionBean/local");
  |             } catch (Exception e) {
  |                     e.printStackTrace();
  |             }
  | 
  |             Collection<User> auser = userSession.getUsers();
  |             if (auser != null)
  |                     for (User user : auser) {
  |                             System.out.println("User name : " + 
user.getName());
  |                             System.out.println("User id : " + user.getId());
  |                             System.out.println("User mgs : " + 
user.getMessage());
  |                     }
  |     }
userSessionBean/local getUsers method code is:

  |     public Collection<User> getUsers() {
  |             // TODO Auto-generated method stub
  |             return em.createQuery("from User u").getResultList();
  |     }

My ejb.persistence.User class is:

  | package ejb.persistence;
  | 
  | import javax.persistence.*;
  | 
  | @Entity
  | @Table(name = "user")
  | public class User {
  |     private String name;
  | 
  |     private int id;
  | 
  |     private String message;
  | 
  |     public User() { }
  | 
  |     public User(String name, String message) {
  |             this.name = name;
  |             this.message = message;
  |     }
  | 
  |     @Id
  |     @GeneratedValue
  |     public int getId() {
  |             return id;
  |     }
  | 
  |     public void setId(int id) {
  |             this.id = id;
  |     }
  | 
  |     public String getMessage() {
  |             return message;
  |     }
  | 
  |     public void setMessage(String message) {
  |             this.message = message;
  |     }
  | 
  |     public String getName() {
  |             return name;
  |     }
  | 
  |     public void setName(String name) {
  |             this.name = name;
  |     }
  | }

Sorry for the long post, hope you're still with me. My questions is:
Why is there a  ClassCastException occured?  What's wrong?

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

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


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to