Can not set java.lang.Integer field ...User.id to java.lang.Integer exception in Hibernate -


i building restful service hibernate jersey , spring on java , realized relationships between entities should without including instance of classes, identifiers (foreign keys). have exceptions when try query entities. have following entities:

@entity @javax.persistence.table(name = "manager_user") public class manageruser extends user {      @manytoone(targetentity = shopadminuser.class)     private integer shopadminuserid; //... }   @entity @javax.persistence.table(name = "shop_admin_user") public class shopadminuser extends user {      @lob     private string contactdata;      public string getcontactdata() {         return contactdata;     }      public void setcontactdata(string contactdata) {         this.contactdata = contactdata;     } }   @entity @inheritance(strategy= inheritancetype.table_per_class) public abstract class user {      @id     @generatedvalue(strategy = generationtype.table)     private integer id;      private string firstname;     private string lastname;      @temporal(temporaltype.date)     private date dob;      @enumerated(enumtype.string)     private gender gender;      @column(unique = true, nullable = false)     private string email;     @column(nullable = false)     private string password;      @lob     private string personaldata;      @onetoone(targetentity = photo.class)     private integer photoid;  //...getters , setters } 

and getting exception in next method:

@transactional(readonly = true) public list<manageruser> getbyshopadminuserid(integer id) {     session session = sessionfactory.getcurrentsession();     list managerusers = session.createquery(             "from manageruser m m.shopadminuserid = :shopadminuserid")             .setparameter("shopadminuserid", id).list();     return managerusers; } 

stack trace:

mar 28, 2015 4:10:56 pm com.sun.jersey.spi.container.containerresponse mapmappablecontainerexception severe: runtimeexception not mapped response, re-throwing http container org.hibernate.propertyaccessexception: not field value reflection getter of com.foodservice.businesslogic.user.shopadminuser.id     @ org.hibernate.property.directpropertyaccessor$directgetter.get(directpropertyaccessor.java:60)     @ org.hibernate.tuple.entity.abstractentitytuplizer.getidentifier(abstractentitytuplizer.java:346)     @ org.hibernate.persister.entity.abstractentitypersister.getidentifier(abstractentitypersister.java:4746)     @ org.hibernate.persister.entity.abstractentitypersister.istransient(abstractentitypersister.java:4465)     @ org.hibernate.engine.internal.foreignkeys.istransient(foreignkeys.java:243)     @ org.hibernate.engine.internal.foreignkeys.getentityidentifierifnotunsaved(foreignkeys.java:293)     @ org.hibernate.type.entitytype.getidentifier(entitytype.java:537)     @ org.hibernate.type.manytoonetype.nullsafeset(manytoonetype.java:174)     @ org.hibernate.param.namedparameterspecification.bind(namedparameterspecification.java:67)     @ org.hibernate.loader.hql.queryloader.bindparametervalues(queryloader.java:616)     @ org.hibernate.loader.loader.preparequerystatement(loader.java:1901)     @ org.hibernate.loader.loader.executequerystatement(loader.java:1862)     @ org.hibernate.loader.loader.executequerystatement(loader.java:1839)     @ org.hibernate.loader.loader.doquery(loader.java:910)     @ org.hibernate.loader.loader.doqueryandinitializenonlazycollections(loader.java:355)     @ org.hibernate.loader.loader.dolist(loader.java:2554)     @ org.hibernate.loader.loader.dolist(loader.java:2540)     @ org.hibernate.loader.loader.listignorequerycache(loader.java:2370)     @ org.hibernate.loader.loader.list(loader.java:2365)     @ org.hibernate.loader.hql.queryloader.list(queryloader.java:497)     @ org.hibernate.hql.internal.ast.querytranslatorimpl.list(querytranslatorimpl.java:387)     @ org.hibernate.engine.query.spi.hqlqueryplan.performlist(hqlqueryplan.java:236)     @ org.hibernate.internal.sessionimpl.list(sessionimpl.java:1264)     @ org.hibernate.internal.queryimpl.list(queryimpl.java:103)     @ com.foodservice.dao.manageruserdao.getbyshopadminuserid(manageruserdao.java:50)     @ com.foodservice.dao.manageruserdao$$fastclassbyspringcglib$$7447621a.invoke(<generated>) ... caused by: java.lang.illegalargumentexception: can not set java.lang.integer field com.foodservice.businesslogic.user.user.id java.lang.integer     @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:167)     @ sun.reflect.unsafefieldaccessorimpl.throwsetillegalargumentexception(unsafefieldaccessorimpl.java:171)     @ sun.reflect.unsafefieldaccessorimpl.ensureobj(unsafefieldaccessorimpl.java:58)     @ sun.reflect.unsafeobjectfieldaccessorimpl.get(unsafeobjectfieldaccessorimpl.java:36)     @ java.lang.reflect.field.get(field.java:393)     @ org.hibernate.property.directpropertyaccessor$directgetter.get(directpropertyaccessor.java:57)     ... 120 more 

edit

my sql provided hibernate

hibernate:      select         manageruse0_.id id1_0_,         manageruse0_.dob dob2_0_,         manageruse0_.email email3_0_,         manageruse0_.firstname firstnam4_0_,         manageruse0_.gender gender5_0_,         manageruse0_.lastname lastname6_0_,         manageruse0_.password password7_0_,         manageruse0_.personaldata personal8_0_,         manageruse0_.photoid_id photoid11_0_,         manageruse0_.systemstatus systemst9_0_,         manageruse0_.usertype usertyp10_0_,         manageruse0_.shopadminuserid_id shopadmi2_6_,         manageruse0_.state state1_6_              manager_user manageruse0_              manageruse0_.shopadminuserid_id=? hibernate:   select     shopadminu0_.id id1_0_0_,     shopadminu0_.dob dob2_0_0_,     shopadminu0_.email email3_0_0_,     shopadminu0_.firstname firstnam4_0_0_,     shopadminu0_.gender gender5_0_0_,     shopadminu0_.lastname lastname6_0_0_,     shopadminu0_.password password7_0_0_,     shopadminu0_.personaldata personal8_0_0_,     shopadminu0_.photoid_id photoid11_0_0_,     shopadminu0_.systemstatus systemst9_0_0_,     shopadminu0_.usertype usertyp10_0_0_,     shopadminu0_.contactdata contactd1_16_0_,     photo1_.id id1_9_1_,     photo1_.image image2_9_1_,     photo1_.name name3_9_1_      shop_admin_user shopadminu0_  left outer join     photo photo1_          on shopadminu0_.photoid_id=photo1_.id      shopadminu0_.id=? 

what doing wrong? me)

i got seem question.now solve it.it's simple. code-->

@manytoone(targetentity = shopadminuser.class) private integer shopadminuserid; 

should

@manytoone(targetentity = shopadminuser.class) @joincolumn(name="shopadminuserid" references...=""(i forget how spell)) private shopadminuser shopadminuser; 

and this:

@onetoone(targetentity = photo.class) private integer photoid; 

should

 @onetoone(targetentity = photo.class) @joincolumn(name="photoid" references...=""(i forget how spell)) private photo photo; 

because hibernate auto converse class int or else


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -