java - Hibernate Exceptions: ClassCastException and QueryException -


i'm kind of new spring mvc bare me. want customer can profilepage. anchor needs click followed:

<a href="${pagecontext.request.contextpath}/customer/profile/${pagecontext.request.userprincipal.name}"></a> 

and have following method in controller:

@requestmapping(value = "/profile/{username}", method = requestmethod.get)     public modelandview editprofileidpage(@pathvariable("username") string username) {          modelandview customereditview = new modelandview("/customer/customerhome");         customereditview.addobject("customer", customerservice.getcustomerbyusername(username));         customereditview.addobject("title", "welkom");          return customereditview;     } 

and next have user model , customer model. left out constructors , of getters , setters minimize code.

user model

@entity @table(name = "user", catalog = "...") public class user implements java.io.serializable {          private string username;         private boolean enabled;         private string password;         private set<storeproperties> storepropertieses = new hashset<storeproperties>(                 0);         private set<userrole> userroles = new hashset<userrole>(0);         private set<customerproperties> customerpropertieses = new hashset<customerproperties>(                 0);          @id         @column(name = "username", unique = true, nullable = false, length = 45)         public string getusername() {             return this.username;         }          @onetomany(fetch = fetchtype.lazy, mappedby = "user")         public set<customerproperties> getcustomerpropertieses() {             return this.customerpropertieses;         }      } 

customer model:

@entity @table(name = "customerproperties", catalog = "...") public class customerproperties implements java.io.serializable {      private int customerid;     private user user;     private string address;     private string city;     private string phonenumber;     private string zipcode;     private string email;      @id     @generatedvalue(strategy = auto)     @column(name = "customerid", unique = true, nullable = false)     public int getcustomerid() {         return customerid;     }      @manytoone(fetch = fetchtype.lazy)     @joincolumn(name = "user_username", nullable = false)     public user getuser() {         return this.user;     }  } 

and method use in dao obtain customerproperties follows:

public customerproperties getcustomerbyusername(string username) {         customerproperties customer = (customerproperties) getcurrentsession()                 .createquery("from customerproperties c inner join c.user u u.username = :user")                 .setparameter("user", username)                 .uniqueresult();         return customer;     } 

when click on link following exception:

 "http status 500 - request processing failed; nested exception org.hibernate.queryexception: not resolve property: user of: com.is202_1.users.model.customerproperties [from com.is202_1.users.model.customerproperties c inner join c.user u u.username = :user]" 

and when change c.user c.user following exception:

 "http status 500 - request processing failed; nested exception java.lang.classcastexception: [ljava.lang.object; cannot cast com.is202_1.users.model.customerproperties"  

can please me?


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -