java - Hibernate @Embeddable class throws "SQLServerException: Invalid column name" for column that is not referenced -
i've been tearing hair out one. have class pulling object so:
public userdto getuser(string login) { string jql = "select entity user entity entity.abcuserid = :userid "; query query = _entitymanager.createquery(jql) .setparameter("userid", login); try { object user = query.getsingleresult(); return ((user) user).extractobject(); } catch(noresultexception e) { log.error(e.getmessage()); return null; } } with class it's pulling:
@entity @table(name="abc_user") public class user implements serializable,entityobject<userdto> { private static final long serialversionuid = 1l; private long id; private string abcuserid; private company company; private list<userpreference> userpreferences; @id @generatedvalue public long getid() { return id; } public void setid(long id) { this.id = id; } @manytoone(fetch=fetchtype.lazy) @joincolumn(name="company_id", nullable=false) public company getcompany() { return company; } public void setcompany(company customer) { this.company = customer; } /** * @return userpreference */ @elementcollection(fetch=fetchtype.eager) @jointable(name="abc_user_preferences") @cascade(value={org.hibernate.annotations.cascadetype.all}) public list<userpreference> getuserpreferences() { if(userpreferences == null) { userpreferences = new arraylist<userpreference>(); } return userpreferences; } /** * @param userpreference userpreference set */ public void setuserpreferences(list<userpreference> userpreferences) { this.userpreferences = userpreferences; } /** * @return abcuserid */ @column(name="abc_user_id", length=10, nullable=false) public string getabcuserid() { return abcuserid; } /** * @param abcuserid abcuserid set */ public void setabcuserid(string abcuserid) { this.abcuserid = abcuserid; } which references embeddable object:
@embeddable public class userpreference implements serializable { private static final long serialversionuid = 1l; private string prefkey; private string prefvalue; public userpreference() {} public userpreference(string key, string value) { this.prefkey = key; this.prefvalue = value; } @column(nullable=false, length=255) public string getprefkey() { return prefkey; } public void setprefkey(string key) { this.prefkey = key; } @column(nullable=false, length=1048576) public string getprefvalue() { return prefvalue; } public void setprefvalue(string value) { this.prefvalue = value; } } so, long winded chunk of code out of way stuff censored, doesn't work. every time try pull user database, throws "sqlserverexception: invalid column name 'user_id'". user_id never referenced in project (i've checked), it's always abc_user. can watch object pulled in eclipse debugger, gets point of adding list of userpreferences , falls apart. if comment out userpreferences portion of user class, pulls (and breaks somewhere else uses them).
what missing?
see following portion of code
@column(name="abc_user_id", length=10, nullable=false) public string getabcuserid() { return abcuserid; } check if table has column name 'abc_user_id'. then, try placing code before @jointable portion
Comments
Post a Comment