spring - java.lang.ClassCastException: java.lang.String cannot be cast to -
i got error while retrieving data database.
java.lang.string cannot cast com.rahul.model.myuser] root cause java.lang.classcastexception: java.lang.string cannot cast com.rahul.model.myuser.
integracontroller.java
@requestmapping("/users") public modelandview users() { list<myuser> p =dq3.usersa2(); (myuser p1 : p){ system.out.println(p1.getusername()); } modelandview m=new modelandview(); m.setviewname("users"); m.addobject("list",p); return m; }
dao.java
@transactional @repository public class dao { private session session; @autowired private myuser u; @autowired private post p; @autowired private person per; @autowired private roles r; @autowired private answer a; @autowired private hibernatetemplate ht; public list<myuser> usersa2() { list<myuser> p2; p2 = ht.executefind(new hibernatecallback<object>() { @override public object doinhibernate(session sn) throws hibernateexception, sqlexception { list<myuser> p1 =sn.createquery("select e.username myuser e").list(); return p1; } }); return p2; }
your query looks this: "select e.username myuser e"
the e.username
part return list of username strings. should from myuser
myuser
objects.
something like:
list<myuser> p1 =sn.createquery("from myuser").list();
Comments
Post a Comment