"richie-lea" wrote : 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; | | } | | } | | Log msg: | | | 06:43:44,937 ERROR [[ejb_servlet]] Servlet.service() for servlet ejb_servlet threw exception | | java.lang.ClassCastException: ejb.persistence.User | | at servlet.ejb_servlet.showUser(ejb_servlet.java:51) | | at servlet.ejb_servlet.doGet(ejb_servlet.java:87) | | at javax.servlet.http.HttpServlet.service(HttpServlet.java:697) | | ..... | | | Sorry for the long post, hope you're still with me. My questions is: | Why did the ClassCastException occured? What's wrong?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3933885#3933885 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3933885 ------------------------------------------------------- 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 JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user